The electoral vote is the one that counts: else, why would we have it? So in this case, the person who won the electoral vote becomes the president.
This rule was introduced because the founding fathers believed that the popular vote can be too easily manipulated...