According to Amendment 12 of the US Constitution, if the election cannot be settled in court, and it cannot be certified with an indisputable majority, the election becomes null and void, and matter goes to the the House of Representatives. At this point, the president will be elected by the House of Representatives.
Source