Christine Ammer, The American Heritage Dictionary of Idioms (1997) has this entry:
in the long run Over a lengthy period of time, in the end. [Example omitted.] This expression, which originated as at the long run in the early 1600s, presumably alludes to a runner who continues on his course to the end. Economist John Maynard Keynes used it in a much-quoted quip about economic planning: "In the long run we are all dead." The antonym, in the short run, meaning "over a short period of time," dates only from the 1800s. The novelist George Eliot used both in a letter (October 18, 1879): "Mrs. Healy's marriage is surely what you expected in the long or short run."
A Google Books Search largely supports Ammer's view that "at the long run" is the older phrase. The earliest match for "in the long run" that it finds is from The Safest-Way with the Dissenters: Being in Answer to a Late Book, Entituled, The Shortest-Way with the Dissenters (1703):
For no sooner was the Toleration Bill passed, and their Preachers set up for lawful Ministers in the Pulpits, but their Laymen set up for Courtiers, and advanc'd themselves to Offices, leaping over the Fence of the Sacrament by the Dispensation and Approbation of their Preachers, which Action but a few Years before would have been Under the Censure of their Churches: Now this Dispensation of their Preachers has in the long run prov'd very Fatal to the Dissenting Interest ; for no sooner were they got into Offices, but they turn'd Knaves, Selling of Offices to any Persons who were the highest Bidders, and sending (for the sake of Lucre) the most deserving of their Party to beg their bread under a Government they had lost their All to Establish ; ...
But the same search finds three matches for "at the long run" from the 1670s. The first of these, Thomas Brooks, London's Lamentations: or, A serious Discourse concerning that late fiery Dispensation that turned our (once renowned) City into a ruinous Heap (1670) uses the expression three times:
So though sore afflictions, though fiery tryals seem to work quite cross and contrary to the Saints Prayers and desires, yet they shall be so ordered and tempered by a skilful and omnipotent hand, as that they shall all issue in the Saints good. At the long-run by all sorts of fiery tryals, the Saints shall have their sins more weakned, their Graces more improved, and their experiences more multiplied, their evidences for Heaven more cleared, their communion with God more raised, and their hearts and lives more amended.
...
But I hope Londons doom is not such [as the destruction of Sodom and Gomorrah] ; for God has given to thousands of her inhabitants a Spirit of Grace and Supplication : which is a clear evidence, that at the long run, they shall certainly carry the day with God.
...
Secondly, Did you improve your estates for the glory of God, and the good of others, or did you not? If not, why do you complain? If you did, the reward that shall attend you at the long run, may very well bear up your spirits under all your losses.
Similar use of "at the long run" appears in Matthew Hale, Contemplations Moral and Divine (1676) and in Richard Gilpin, Daemonologia Sacra: Or, A Treatise of Satan's Temptations (1677). Like Brooks, Gilpin uses the phrase three times in his treatise; Hale uses it four times in his.
None of the idiom dictionaries I consulted (aside from Ammer) hazards an opinion as to the origin of the phrase. But certainly the preachers who gravitated toward "at the long run" in the 1670s seem to have had in mind a meaning along the lines of "when events have run their course."