I'll post about 1824, when John Quincy Adams became the President despite losing both the popular and the electoral college vote.
How? Andrew Jackson won the most electoral college votes, but he didn't win a majority. If no candidate receives a majority of the electoral college, the House of Representatives determines the winner. John Quincy Adams won the election in the House, mainly because he held the support of Henry Clay, the Speaker of the House, who ultimately rallied the votes necessary for Adams to win the Presidency.
Clay certainly didn't like Jackson and generally supported the Adams platform of internal improvements. Related was Adams' decision to offer Clay the position of Secretary of State, although it's not totally clear (at least to me) whether the offer was truly necessary for Adams to win Clay's support. Jackson supporters certainly believed it was and accused Adams and Clay of a "corrupt bargain."More questions on U.S. Presidents: