A contested result and the risk of civil unrest would pose a dilemma for Congress, courts and the military.
As Americans prepare to cast their vote in the US election, a nightmare scenario looms large: what if Donald Trump were to lose the presidency but refuse to accept defeat?
Trump has repeatedly refused to commit to accepting the election outcome, predicted widespread fraud, and claimed that the results from postal voting — which is expected to surge because of the coronavirus pandemic — might not be known "for months or for years".
His Democratic rival Joe Biden has accused Trump of trying to steal the election and claimed the military would escort him from the White House if he refused to leave.
With the stage set for a dramatic showdown in the event of a close-run result, a constitutional crisis could play out against the backdrop of violent unrest in the streets — something that has flared in several US cities in recent months.
The Supreme Court and Congress might play a role in determining who takes the Oval Office. But legal scholars stress that resolving a disputed election should come down to good faith and a willingness to reach a compromise. In short, one candidate and their party would have to accept they have lost.
Edward Foley, a professor at Ohio State University who has studied the vulnerabilities in the US election system, said that both sides have defined the election as an existential test for the country, which would "make it hard to concede defeat".
Much rests on the character and calculations of Trump and Biden, although neither would be able to dispute the election without the backing of state and federal party machinery.
"The candidate can't just [create a crisis] by himself," Foley said. "They're going to need some institutional players in the system to support their moves."
It would not be the first time in recent history that the US political class has waged legal warfare after polling day. In 2000, court battles between George W Bush and Al Gore over vote counting in Florida escalated to the Supreme Court, which ruled in Mr Bush's favour by stopping a recount. Gore conceded, rather than escalate the fight to Congress.
David Boies, who argued for Mr Gore at the Supreme Court, said he thought it was unlikely America's top court would again intervene to in effect decide the outcome.
"If they did, I think there are many including myself that would urge Biden . . . to take [his] case to the Congress," he said. Under the constitution, it is Congress that has responsibility for counting Electoral College votes.
Any election dispute will probably unfold in three phases after polling day. States have until December 8 to resolve any disputes over the vote, with state electors casting their Electoral College votes on December 14.
The newly elected Congress then tallies those votes on January 6, in a joint session led by Mike Pence, the incumbent vice-president who is also president of the Senate.
If there were still no agreement, the US would be in a third, deeply destabilising phase, akin to the disputed 1876 election when several states sent competing electoral college votes to Congress and the crisis was only resolved two days before inauguration. The 1887 Electoral Count Act sought to avert a repeat of such chaos but today's political parties could interpret it differently.
In the event that no president is chosen by inauguration day on January 20, an acting president would serve as a caretaker. According to succession laws, this would be Nancy Pelosi, the Speaker of the House and a Democrat, if she retains her position in the new Congress.
But Republicans and Democrats might both claim that their candidate is the clearly chosen winner, meaning that Pelosi could not step in. Determining the outcome in such an unprecedented scenario would rely on political and popular pressure, and ultimately compromise.
"That process depends in large measure on the good faith of the participants in it, including the Congress, if it ever got to that point," said George Terwilliger, a lead lawyer for Bush in his battle with Gore in 2000.
"I think there would be political ramifications going forward to people who put politics ahead of the welfare of the nation," he added.
Such uncertainty amid high expectations for victory on either side risks civil unrest that increases pressure for one side to concede, officials fear. It could also pit the military against civilians who have taken to the streets.
"Leaders are already thinking through the potential for unrest," said a former senior military officer in touch with top Pentagon officials.
Pentagon leadership has insisted the US military has no role to play in any election dispute and has openly discouraged Trump from invoking the 1807 Insurrection Act, which would give him the authority to deploy troops to quell any civil unrest.
However, in an open letter published last month, two highly regarded military strategists, both army veterans, suggested General Mark Milley, America's top uniformed officer, should order the US military to forcibly remove Trump if he refuses to leave office.
Kori Schake, an expert in civil-military relations at the conservative American Enterprise Institute, dismissed their proposition as unconstitutional and dangerous. If anyone were to escort a losing president from the White House, it would be the Secret Service, not the military.
But Schake said she was worried that Trump could stoke violence on the streets. "I do fear the potential of armed mobs being fomented by the president," she said.
In the event of civil unrest, any role for the military would probably centre on the National Guard, the 450,000-strong reserve force drawn from local communities that was deployed on to the streets this summer when some anti-racism protests turned violent.
Gen Milley, who commands no troops but is Trump's top military adviser and chairman of the joint chiefs of staff, has said publicly he would not follow an unlawful order. In June, he apologised for appearing alongside the president in battle fatigues after peaceful protesters were forcibly removed from outside the White House.
In a written response to two Democratic members of the House armed services committee released late last month, he dismissed the notion the military would play any role in determining the presidency, saying courts and Congress would have to resolve any dispute.
"I, along with the entire US military, will follow the lawful orders of the legitimate president of the United States as determined by law," said Gen Milley, adding US law stipulated there could only be one lawful president at a time.
Mark Esper, the defence secretary, has not addressed the issue. In June, he apologised for referring to domestic US soil as the "battlespace", and drew Trump's ire for arguing against invoking the Insurrection Act.
Constitutional chaos: A possible worst-case scenario, where Pennsylvania is the 'tipping point' state
In one possible election scenario, the swing state of Pennsylvania, with its Democratic governor and Republican legislature, is the key to the White House. It was crucial to Trump's victory in 2016 and the race in the state is likely to be tight again. If Biden takes its 20 electoral votes he secures the presidency under this scenario. If, however, Trump prevails in Pennsylvania, he secures four more years.
Is there a clear-cut winner in Pennsylvania on election night?
YES: Either Trump or Biden declares victory and the result goes uncontested.
NO: Trump declares victory, but Biden, urged by his advisers to hold his nerve, says the race is not over and expresses confidence that a full count will show he has won.
Trump's narrow margin erodes as more mail-in ballots are counted. Democratic state election officials press on at full speed with the count.
Trump sues to stop the tally, claiming the mail-in ballots are fraudulent. The legal battle works its way up to the US Supreme Court, which declines to order a halt.
The deadline for resolving poll disputes under the 1887 Electoral Count Act. Biden has taken a narrow lead and Democratic state election officials call the vote for him.
Does Trump concede?
YES: Republicans are unwilling to plunge the country into a crisis it has not seen for more than a century. Besides, they have held the Senate, which will be a powerful check on Biden's presidency. Biden wins.
No: Trump, with the backing of his party, says he will take the election fight to Congress, which under the constitution has responsibility for counting Electoral College votes.
On this day, votes in the Electoral College must be cast by so-called electors — groups that represent each state and are typically made up of party leaders, local elected officials or activists.
Under Pennsylvania election law, the governor has responsibility for signing and transmitting the votes of the state's electors.
He signs the votes of Democratic electors, who all back Biden in line with the declared popular vote result, and transmits them to Congress
A slate of GOP electors votes separately for Trump at the bidding of the Republican-controlled legislature, which transmits those votes also, citing Article 2 of the constitution to support the move.
The newly elected House and Senate meets to count the Electoral College votes.
Mike Pence, as president of the Senate, oversees the count in line with the constitution.
When it comes to Pennsylvania, the Democrat-controlled House and Republican-controlled Senate split on which votes to accept.
Pence claims constitutional authority to break the logjam and decrees that votes submitted by Republican electors are the lawful ones, sparking outrage by Democrats, who halt the count.
Do Democrats and Republicans agree that no president has been selected?
Yes: The constitution and federal succession law require that Speaker, Democrat Nancy Pelosi, becomes acting president if no president and no VP are picked by inauguration day.
There is agreement about what will happen come January 20.
NO: Pence and congressional Republicans complete the Electoral College count in the absence of Democratic lawmakers, recording Pennsylvania's votes for Trump, thereby declaring him president and Pence vice-president. Democrats are united in opposition, saying Trump has launched a coup.
The US approaches inauguration day with uncertainty about the transfer of power.
Will the Supreme Court intervene?
Yes: The court is asked to rule on whether a president has been selected, and also on the status of Pennsylvania's votes. Its decision ends legal uncertainty about the succession.
Trump or Biden wins, or Pelosi becomes acting president.
No: The justices view the dispute as inherently political, and not suitable for the court to decide, especially when a 5-4 decision along partisan lines could inflame as much as resolve tensions.
Inauguration day. There is no consensus about who is president. Mr Trump remains in the White House. His first term ends, as required by the constitution. He claims his second term has just begun.
Written by: Katrina Manson and Kadhim Shubber
© Financial Times