They were technically voting for 538 electors who, according to the system laid out by the Constitution, meet in their respective states and vote for President and Vice President once the popular vote totals are completely counted and certified.
Americans have been refining this process since the election of 1800, which originally resulted in an Electoral College tie. The House of Representatives gave Thomas Jefferson the presidency and that first disputed election resulted in the 12th amendment, which modified the Electoral College process.
Later, in 1824, John Quincy Adams got to the White House despite not winning either the popular vote or a majority in the Electoral College.
In 1876, the results in several Southern states were disputed, and the lack of clear Electoral College results led to a deal in the House that gave Rutherford B. Hayes the presidency even though he won neither the Electoral College nor the popular vote. That ultimately begat the Electoral Count Act of 1887, which is still in effect today.
The whole timeline is below.