One of the most widely used words on Earth started as a newspaper in-joke about bad spelling.
In the late 1830s, Boston papers were playing a game. Writers took a common phrase, misspelled it on purpose, then abbreviated the misspelling. Wikipedia's account lists examples such as "O.W." for "oll wright" and "N.G." for "no go." Etymonline adds "K.G." for "no good." Most of these vanished within a few years.
One survived. On March 23, 1839, the Boston Morning Post printed "o.k." with the gloss "all correct." The piece, attributed to the editor Charles Gordon Greene, was a comic item about a local society. "O.K." stood for "oll korrect," which made sense only as a joke on "all correct."
Politics then gave the fad a second meaning. In the 1840 presidential race, supporters of the Democratic incumbent, Martin Van Buren, formed an "O.K. Club." Van Buren came from Kinderhook, New York, and was nicknamed "Old Kinderhook." The initials now worked twice. Etymonline notes that his Whig opponents used the letters too, which only spread them further. Van Buren lost the election, but OK stayed.
For a century, nobody was sure where the word came from, and rival theories flourished. One traced it to the Choctaw word okeh, "it is so." Woodrow Wilson was persuaded enough to write "okeh" on documents he approved. Others proposed West African languages, Scots och aye, or Greek ola kala, "all good." None of these has documentary support linking it to the American word.
The question was settled by the linguist Allen Walker Read. In a series of articles in the journal American Speech in 1963 and 1964, he traced OK back through old newspapers to the Boston abbreviation craze. His findings are now the consensus of Etymonline, Merriam-Webster and most historians of the word.
The spelling "okay" arrived later, around 1929, according to Etymonline. It is easier to inflect, as in "okayed," so it became common in edited prose. The word also grew new forms: OK as a noun meaning approval by 1841, and as a verb meaning "to approve" in the 1880s. Merriam-Webster dates the verb to 1882, Etymonline to 1888.
Today OK is used in languages far beyond English, usually unchanged. A joke about misspelling "all correct" turned out to be the most durable spelling mistake in the language.