Americans have been refining this process since the election of 1800, which resulted in an originally electoral college tie. The House of Representatives gave Thomas Jefferson the presidency and that first disputed election resulted in the 12th Amendment, which revised the electoral college process.
Later, in 1824, John Quincy Adams went to the White House despite not winning the popular vote or majority at Electoral College.
In 1876, the results were disputed in many southern states, and the lack of clear electoral college results led to a deal in the House that allowed Rutherford b. Gave Hess the presidency even though he neither won the Electoral College nor the popular vote. Eventually the Electoral Count Act of 1887 came into force, which is still in force today.
The entire timeline is below.