What happens if the president dies during the election?
There are holes in our democratic process of succession

America has seen the death of presidential candidates; America has seen the death of presidents. Thus far, those two events have happened separately, and America has avoided a major crisis in the presidential succession process. Even after the passage of the 25th Amendment, however, the presidential election system is vulnerable to badly-timed deaths.
Presently, President Donald Trump is in ill health, may have infected rival candidate Joe Biden, and a presidential election is already underway. If he, Biden, or both were to die any time between now and December 14th, it could lead to a major electoral crisis.
The open window in the Electoral College
Ordinary American citizens have already begun to vote for president. Technically speaking, however, an ordinary citizen’s vote for president is actually a vote for a slate of electors. It doesn’t matter whether or not the presidential candidates die; a vote for a presidential ticket is counted as a vote for that ticket’s designated electors.
In the fifty-ninth presidential election of the United States, electors will vote on December 14th, 2020. They will meet meet in fifty-one separate assemblies. If a presidential candidate has a majority of the electoral vote but dies after electors vote but before inauguration, the winning vice presidential candidate simply becomes president, per the 20th Amendment.
If a presidential candidate dies before December 14th, things get messy. In a close election, this means it is likely that the president will be elected via House contingent election.

Votes for dead candidates are invalid; this precedent was set in 1872 when Horace Greeley died before electors met. Any presidential electors who vote for a dead candidate — whether because they are required by state law to vote a certain way or because they simply don’t know what else to do — will waste their vote.
The electors belonging to the dead candidate’s party will decide how to vote. Neither major party has an easy way to choose a replacement presidential candidate fairly — or to compel electors to vote for that replacement candidate.
The running mate problem
There is one obvious natural choice for a replacement candidate: The vice presidential candidate. After all, this is who would become president if the presidential candidate died after electors met.
Unfortunately, many electors may be pledged to cast their vice presidential vote for their party’s running mate — even if their presidential vote is released, they may be required by the state to vote as pledged for vice president. Casting both votes for the same candidate has its own complications: If electors cast both of their votes for the same candidate, they risk handing the vice presidency to the opposing party.
On top of those complications, the electors may not want to vote for the vice presidential candidate. Vice presidential candidates are often chosen for strategic or symbolic reasons, rather than as credible replacements for the president. In 1872, Horace Greeley’s running mate, Benjamin Brown, placed third in the Electoral College, with 18 votes; another Democrat, Thomas Hendricks, gained 42 votes with the endorsement of many key Democratic leaders.
The contingent election process
It is very likely that if the apparent winner dies before electors vote, no presidential candidate will have a majority of the votes in the Electoral College. If a significant number of electors also change their vice presidential votes, it’s also possible that no vice presidential candidate will have a majority in the Electoral College, either; remember, votes for president and vice president are separate.
If no vice presidential candidate gets a majority, the Senate votes between the top two candidates. This happens under fairly normal rules, with a minimum of 67 senators required for a quorum and 51 votes required to win:
[T]he Senate shall choose the Vice-President; a quorum for the purpose shall consist of two-thirds of the whole number of Senators, and a majority of the whole number shall be necessary to a choice.
It is theoretically possible for the minority party to block a decision by walking out and preventing a quorum. Currently, there are 53 Republican senators. For the Senate contingent process to deadlock requires very unusual circumstances, since each senator votes individually. The rules for the House contingent election, however, are slightly different.
[F]rom the persons having the highest numbers not exceeding three on the list of those voted for as President, the House of Representatives shall choose immediately, by ballot, the President. But in choosing the President, the votes shall be taken by states, the representation from each state having one vote; a quorum for this purpose shall consist of a member or members from two-thirds of the states, and a majority of all the states shall be necessary to a choice.
In the House contingent election process, state delegations can tie, and there are an even number of states. Further, the top three candidates are eligible. This means that the House contingent election process is prone to deadlocks, especially if the House is closely divided.
If no presidential candidate gets a majority, then the House of Representatives decides who becomes president — using the old-fashioned “one state delegation, one vote” rule once used by the Continental Congress. If neither party gains significantly in the current Congressional elections, Republicans would have a narrow 26–23 majority in the House contingent election process — but that could change easily.

Pointedly, in 1800, the House deadlocked for thirty-six ballots in a row, as a Federalist majority in Congress was deciding between two Democratic-Republicans (Thomas Jefferson and Aaron Burr). It’s worth noting that while extremely unlikely, a candidate dying during an extended contingent election process would have significant political consequences.
What happens if the House does not elect a president
If the House contingent election deadlocks past January 20th, and a vice president has been elected, the vice president becomes president. This can happen even if neither presidential candidate dies; a 269–269 tie in the Electoral College would do the trick.
If, on January 20th, there is neither a newly elected president nor a newly-elected vice president, the Speaker of the House will become president under the current terms of the Presidential Succession Act. It remains to be seen who will be Speaker of the House, since the 117th Congress will begin on January 3rd.
This could happen if both the House and Senate contingent election process deadlock; if the winner for one office dies after electors vote and the contingent election process for the other office deadlocks; or if both winning candidates die after electors vote. All of these cases are very unlikely, but are currently less unlikely than usual.
Recap
If Donald Trump or Joe Biden die sometime between now and December 14th, but their ticket wins a majority of electors, it’s likely to kick off a messy process involving a last-minute scramble to designate a replacement presidential or vice presidential candidate and one (or even two) contingent elections. In the worst case, this could lead to a reversal where a candidate who seemed to lose on election night is nevertheless appointed into office by Congress.
If, on the other hand, the candidate who dies is on track to lose in the Electoral College, or holds on until after electors vote on December 14th, the resulting succession is as normal and predictable as possible.