If no candidate receives a majority of the electoral votes, then the decision is made in the House of Representatives where each state's delegation has one vote. The presidential election has not formally been decided by the House since 1824. Congress did, however, decide the 1876 contest between Hayes and Tilden, where the loser was elected, and chose Gerald Ford by forcing Nixon from office. By recent tradition, voters in every state except Maine and Nebraska elect an at-large slate of electors. In the early years of the republic, electors were sometimes chosen by congressional district.
Electors are free to vote for any candidate they choose.
That is why the major party electors are usually the most faithful party adherents that the candidate can find. When electors vote for someone other than the candidate to whom they originally pledged themselves, they are called faithless electors. In 1976, one Washington elector voted for Reagan instead of Ford. It didn't make any difference because Carter won the election. In 1972, one Virginia elector voted for the Libertarian candidate, Hospers, instead of Nixon.