The way we elect the president and vice president in the U.S. is quite unique compared to the way we elect every other elected office. We don't elect them directly. Instead, we vote for electors who then cast votes for a presidential ticket.
Electors from each state are supposed to cast their votes for whichever candidate won that state's popular vote -- "winner takes all." However, every once in awhile there is a rogue elector who casts a different vote as "winner takes all" is not required by law in all states.