He was again the presidential candidate of the Democratic party in 1840, but he was defeated in the "log cabin and hard cider" campaign by William Henry Harrison. The Whigs unfairly painted Van Buren as a man of great wealth who was ignorant of, and disdainful toward, the common people. In 1844, Van Buren was the leading possibility as Democratic candidate for the presidency, but he flatly opposed the annexation of Texas because he felt it would provoke war with Mexico and because he opposed the extension of slavery. Although he held a majority in the nominating convention, he was unable (largely as a result of the efforts of Robert J. Walker) to obtain the two-thirds majority necessary to win the nomination. Van Buren, bitterly disappointed, saw James K. Polk elected President.
He remained prominent in Democratic party politics, and helped lead the Barnburners in their violent struggle with the Hunkers. In 1848 he was the presidential candidate of the newly organized Free-Soil party and managed to take enough New York votes away from the Democratic candidate, Lewis Cass, to aid Zachary Taylor, the Whig party candidate, in winning the election. He voted for the Democratic candidate in the elections of 1852, 1856, and 1860, but supported Abraham Lincoln during the secession crisis. An Inquiry into the Origin and Course of Political Parties of the United States (1867) was written by Van Buren, edited by one of his sons, and published posthumously.