Originally the term “dark horse” was a racing term for a horse about which nothing was known; its abilities had been kept “in the dark”, secret, that is, until it appeared on the track.
Benjamin Disraeli is credited with the first literary usage in that sense in The Young Duke (1831): “A dark horse, which had never been thought of, rushed past the grand stand in sweeping triumph.”
Though a recent anonymous newspaper columnist attributes the origin to a “dark colored horse named ‘Dusty Pete'” owned by a Tennessean, “Sam Flynn,” who “used to ride from town to town” entering the horse, which appeared to be lame, in local races and snapping up the money, the story is another instance of folk etymology.
Disraeli, both before and after entering the British political arena, was a popular writer, accepted in America as in England.
Accordingly, when, to break the deadlock in the Democratic convention of 1844 among the adherents of Van Buren, Lewis Cass, and James Buchanan, the name of James K. Polk was introduced on the ninth ballot, he was the “dark horse” that had not been thought of, and this was the actual introduction of the term into political usage.