Four different presidential candidates in U.S. history won the popular vote and still lost the election.
The first record of this happening was in 1824. This was also the first election in which records of the popular vote were kept. Strangely enough, Andrew Jackson received the most popular votes in the election AND the most electoral votes in the Electoral College, and he STILL lost the presidency. The winner, John Quincy Adams, was selected by the House of Representatives. On the bright side, Jackson defeated Adams four years later in the next election.
In the United States, the president is elected by an Electoral College, made up of representatives, called electors, from each state. In order to win the presidency, a candidate needs to carry a majority of the electoral votes. In 1824, there were 4 major candidates (Jackson, Adams, William Crawford and Henry Clay), and while Jackson won the most popular and electoral votes, he fell short of a true majority of the votes. Since the election was inconclusive, the House of Representatives had to decide the winner among the top 3 candidates (Jackson, Adams, and Crawford). Clay offered his support to Adams, so Adams received the most votes in the House and became president.
There were 3 more elections where the winner of the popular vote winner didn't win the presidency. The most recent was Al Gore, who lost the 2000 election to George Bush. The other 2 were in 1876 and 1888. You can read more about the unusual circumstances surrounding these elections here.