It is not generally known that we have had several Presidential candidates who lost the Presidency in very close races, where one could note that a small switch of votes would have changed the result, with five such cases in American history. And some Presidential candidates have lost despite winning the national popular vote, with four such cases in American history. So therefore, nine elections saw these scenarios.
Andrew Jackson lost the Election of 1824 to John Quincy Adams despite winning the national popular vote by about 45,000.
Henry Clay lost the Election of 1844 to James K. Polk by losing New York State by about 5,000 votes.
Samuel Tilden lost the Election of 1876 to Rutherford B. Hayes despite winning the national popular vote by about 250,000.
James G. Blaine lost the Election of 1884 to Grover Cleveland by losing New York State by about 1,000 votes.
Grover Cleveland lost the Election of 1888 to Benjamin Harrison despite winning the national popular vote by about 100,000.
Charles Evans Hughes lost the Election of 1916 to Woodrow Wilson by losing California by about 3,800 votes.
Richard Nixon lost the Election of 1960 to John F. Kennedy by losing the state of Illinois by about 8,000 votes.
Gerald Ford lost the Election of 1976 to Jimmy Carter by losing the state of Ohio by 5,600 votes and the state of Hawaii by 3,700 votes.
Al Gore lost the Election of 2000 to George W. Bush despite winning the national popular vote by 540,000, and by losing the state of Florida by 537 votes.
Of course, Jackson, Cleveland, and Nixon went on to win the next national election in each case, and Ford, although never being elected, had the satisfaction of having been President for almost two and a half years.
Tilden and Gore were the most tragic cases, as they never ran again for President, and yet had won the national popular vote in each case.
Henry Clay and Charles Evans Hughes were exceptional public servants in so many ways, but would never be President.
Finally, James G. Blaine losing was probably good, as he was regarded as the most corrupt national candidate in American history!