There have been a couple of cases where a candidate won the electoral college despite losing the popular vote.
In 2016, Donald Trump lost the popular vote but won the electoral college.
In 2000, George W Bush lost the popular vote by about a half million votes but won the electoral college.
In 1888, President Grover Cleveland got more popular votes but lost the electoral college to challenger Benjamin Harrison.
There are two other instances which are slightly different than how the 2016 election played out. In 1876, Republican Rutherford B Hayes was running against Democrat Samuel Tilden. In the end, Tilden got more popular votes, but a couple of Southern states, enough to decide the race, issued two conflicting sets of returns. Congress convened a special commission to decide the election and they awarded all the states, and their electoral votes, to Hayes. Hayes was denounced by many at the time as "Rutherfraud" Hayes, but a wrinkle in this is that Southern states saw massive voter suppression directed against black voters (who at the time voted almost exclusively for Republicans). If they had been allowed to vote freely then they would have certainly delivered several Southern states to Hayes.
The other one which is slightly different is the 1820 election. That election, held before modern parties existed, saw a four way race between Secretary of State John Quincy Adams, General Andrew Jackson, Treasury Secretary William Crawford and Speaker of the House Henry Clay. Jackson ended up getting the most popular votes and electoral votes, but no candidate actually got a majority of the electoral votes. In cases like that, the Constitution sends the decision for president to the House of Representatives, which gets to decide among the top three finishers. This ruled out Clay, who finished fourth, but since he hated Jackson, he swung his support behind Adams, who ended up being selected as president, despite finishing second in both the popular vote and electoral vote counts. The controversy over this election outcome helped create the Democratic Party, which was organized by Southern Andrew Jackson and Northerner Martin van Buren.