Allen Walker Read traced OK to the Boston Morning Post of March 23, 1839, in a series of papers now standard in American lexicography. The 1840 Old Kinderhook campaign spread it nationally. Earlier proposed origins, Choctaw okeh, West African loanwords, Andrew Jackson's initials, are all evaluated and rejected or left unproven by Read's documentation.
The rival theories are the fun part: Choctaw okeh, meaning it is so, which would make OK one of America's great indigenous loanwords, and West African waw-ke or Mande o ke, carried by enslaved speakers. Both are phonetically plausible and historically serious; Read judged the newspaper trail stronger.
Read himself noted the meta-lesson: OK spread because it was maximally compressible, two letters carrying assent, and every telegraph, telephone, and keyboard since has rewarded exactly that. The joke word won because infrastructure has taste.
A joke abbreviation and a failed presidential campaign jointly produced the most successful word ever. What does that imply about where language actually comes from?