Americans have been refining the 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.