Even as Donald Trump was announced winner of the American Presidential election, we knew that Hillary Clinton had a slim lead in the popular vote. As I write this, that lead may exceed two million votes. Why was Hillary not declared the winner? Because Trump had been deemed to have won the majority of Presidential electors, those who vote for President as members of the Electoral College.
EDIT: Consider the Brexit. As I understand it, cities voted REMAIN but not by enough votes to counter the LEAVE vote in rural areas. Very similar in the US Presidential election but with the added layer of the state-by-state Electoral College to consider. Clinton may have won New York State and California by huge margins but the margins make no difference. She still only gets the votes of their allotted number of electors. Trump won enough states, regardless of the margin, to earn the victory.
First, how does the Electoral College work?
The choosing of electors and the manner in which they are to vote is a question left up to the individual states. Each state is apportioned electors equivalent to their Congressional delegation. Washington DC participates and has the same number of electors as the least populous state. In 48 states and DC, electors are all expected to vote for the candidate who gets the most votes state wide...winner take all. Two states apportion electors by vote within each Congressional district with two additional at-large electors representing those states' Senators.
In essence, when an American votes in a Presidential election, the vote is cast for a slate of electors representing that candidate and not simply for the candidate. The candidate winning a majority of electors wins the Presidency.
There have been what are called 'faithless' electors, electors voting for a candidate other than the one that has been certified as winning that state or district. Some states have laws that would punish faithless electors after their vote. One state would void the vote of a faithless elector. Many states don't address the issue. And there is no certainty how the Supreme Court would rule on faithless elector laws. They have never been invoked against a faithless elector, primarily because faithless electors have never changed the outcome of an election.
A tie in the Electoral College leads to a vote in the House of Representatives. A tie in the House leads to a vote in the Senate. As is the case with any tied Senate vote, a tie in the Senate would be decided by the sitting Vice President acting in his Constitutional capacity as President of the Senate.
Those are the mechanics.
What drove the Framers to create such a system? Some would say that the Electoral College was designed protect small states from larger ones. Others argue that the Electoral College ensures that an unqualified candidate would not become President. While both arguments have some merit and quotes from Founders can be cited in their defense, the overwhelming evidence points to a different cause - power politics wielded by the slave holding states during the Constitutional Convention.
Prior to adopting the Constitution, the thirteen British colonies were in essence sovereign countries with their own chief executives, their own legislatures, and their own armies (militias). The necessity of maintaining a strong union while waging a war for independence was a relatively easy sell. After independence had been won, the benefits of a federal union were not so apparent. Such a federation inherently meant that the sovereign states would be ceding a certain amount of their sovereignty to the new federal government. Two intertwined questions came to the fore as the question of the power of individual states to influence the new federal entity was negotiated. How would we elect a nationwide President? How would we apportion representation in the House of Representatives?
Although some like Madison favored direct election of the President by vote of the people, the Framers did not have great faith in pure democracy. They were, after all, the elite of their time - tax-paying, land-holding free men, one and all. The first proposal brought before the Constitutional Convention was that the House of Representatives would elect the President. That idea failed due to concerns that the Chief Executive would be too beholden to the Legislative Branch under such an arrangement. There was also worry that the House, a small group of men that met regularly, might devolve into a cabal, electing a President through nefarious, secret dealings. Thus, the The Great Compromise that included the Three-fifths Compromise prevailed.
The Framers decided that a national census would be conducted every ten years. House delegations would be apportioned by population. More populous states would have larger delegations. Less populous states would be protected by a Senate that gave each state two Senators - large state or small, the same number. Simple? Not so much. What about slaves?
According to the 1790 census, there were approximately 700,000 slaves in a total population of just under 3,900,000 - 18% of the population. The slave states wanted those slaves to be counted the same as free men and women to beef up their House delegations. The free states didn't want them counted at all. Thus the Three-fifths Compromise.
...[representation] shall be determined by adding to the whole Number of free Persons, including those bound to Service for a Term of Years, and excluding Indians not taxed, three fifths of all other Persons.
~Article 1, Section 2, Paragraph 3 of the United States Constitution
So, slaves accounted for about 11% of the population used to determine Congressional representation and electors. Is it any wonder that nine of the first fifteen Presidents came from slave states, that seven of those nine came from Virginia with its 300,000 slaves in 1790, and that after the Civil War the first Southerner from one of the original slave states to be elected President who wasn't first elevated to the job by death or assassination was Jimmy Carter?
The Electoral College. Power politics, played skillfully by slaveholders.