The 'Founding Fathers' of the United States, who wrote the Constitution, by which the Electoral College was established, were concerned with what they might have called 'the passions of the masses'. In other words, they were concerned that the mass of people who could vote in a presidential election would be more influenced by human emotions, especially negative emotions -- fear, hatred, jealousy, etc..., than they would be by their ability to think logically, to reason. They were afraid that this would lead unscrupulous candidates running for the presidency to manipulate voters into electing them, not on the basis of their qualifications to be president, but on the basis of the voter's fears, hatreds, jealousies, etc...
The Electoral College was intended to serve as a 'brake' on 'the passions of the masses' by adding a parallel means of electing a president. Individuals qualified to vote for a candidate running for the presidency (note that the qualifications initially were far more limited than they are today) represents an example of 'Direct Democracy'. The Electoral College represents an example of 'Indirect Democracy'. Indirect democracy involves qualified voters voting for an individual - in this case a candidate for the Electoral College, known as an 'Elector' - who, once chosen by the majority of the voters, will, in turn, exercise his or her ability to cast a vote for a person running for a political office - in this case, the presidency. In short, a system of voters electing voters.
In a system of indirect democracy, the individual who is elected by the voters is elected to cast a vote, but they are free to use their judgement as to for whom they will cast their vote. For example, if a person is elected to the Electoral College by a majority of voters who happen to be members of the Democratic Party, that person, who would now be an Elector in the Electoral College, does not have to vote for the candidate of the Democratic Party running for the presidency. This Electors are supposed to be free to use their own judgement as to which candidate running for the presidency is the best qualified for the office.
It was in this way that the Founding Fathers sought to guard against 'the passions of the masses'. Even if a person who was clearly unfit to serve as president managed to convince the majority of voters to vote for him / her, and thus was the winner in the system of Direct Democracy, this person would still have to win the majority of votes from the system of Indirect Democracy, the Electoral College. The Founding Fathers were counting on the Electors of the Electoral College, who were free to vote for any of the candidates for the presidency, to recognize when the majority of voters had chosen a candidate who was clearly unfit to serve as president. Using their good judgement, the Electors would then vote for a different candidate, different from the one elected by the system of Direct Democracy, the candidate - in the eyes of the majority of the Electors - .who was the most qualified to serve as president.