The presidential candidates need 270 electoral votes to win. In the unlikely event of a tie, the vote goes to the house with each state having one vote.
Three times in the more distant past a candidate with the largest popular vote has lost the election.
In 1824 Andrew Jackson was the vote leader among four presidential candidates. None of the four got an electoral majority. The election was decided in the house and John Quincy Adams won.