The etymology of OK was described by renowned Columbia University professor Allen Walker Read in a series of articles in the journal "American Speech" in 1963 and 1964. The letters stand for "oll korrect." They're the product of a trend for amusing abbreviations that thrived in the late 1830s and 1840s.
Professor Read supported his assertion with hundreds of citations from newspapers and other documents of the period. The abbreviation fad began in Boston in the summer of 1838 and spread to New York and New Orleans in 1839. Boston newspapers began referring mockingly to the local swells as OFM, "our first men," and used expressions like NG, "no go," GT, "gone to Texas," and SP, "small potatoes."
Many of the abbreviated expressions were embellished misspellings. One forerunner of OK was OW, "oll wright," and there was also KY, "know yuse," KG, "know go," and NS, "nuff said."
The majority of these acronyms were only briefly popular. But OK was different, probably because it was so versatile. It was first used in print in Boston in March of 1839 and soon became pervasive among trendy folks of the time.
It didn't become ubiquitous, however, until 1840 when Democratic supporters of Martin "Old Kinderhook" Van Buren adopted it as the name of their political club -- the OK Club. Van Buren's opponents tried to turn the phrase against him, by coming up with unflattering interpretations like "Out of Kash, Out of Kredit, and Out of Klothes."
Newspapers around the country enjoyed coming up with even goofier interpretations like Oll Killed, Orfully Konfused, and Often Kontradicts. By the time the presidential campaign was over the expression had taken firm root nationwide.