The president pulled every lever to stay in power. Ultimately, it did not work. The United States must decide how it will handle the next election, especially if the outcome is closer.

In the end, the coup did not take place. In the most grudging manner possible, Donald Trump signaled on November 23 that the transition of power could begin. That, a White House official told reporters, was as close as Trump will probably ever come to concession, but the machinery of transition has gathered momentum.

Joe Biden’s incoming administration now has a government internet domain, is being briefed by government agencies and is due to receive federal funding. The Pentagon quickly announced it would be providing support for the transfer of power. And one by one, senior Republicans – an especially timid category – are recognizing the election result.

But there is no doubt American democracy has been given a scare. As the sense of imminent threat begins to fade, the convoluted inner workings of the electoral system are coming under scrutiny to determine whether it was as robust as its advocates had hoped – or whether the nation simply got lucky this time.

“I had long been in the camp of people who believed that the guardrails of democracy were working,” Katrina Mulligan, a former senior official in the justice department’s national security division. “But my view has actually shifted in the last few weeks as I watched some of this stuff play out. Now I actually think that we are depending far too much on fragile parts of our democracy, and expecting individuals, rather than institutions, to do the work the institution should be doing.”

Trump made no secret of his game plan even before the election, and it has come into sharper focus with every madcap day since: cast doubt on the reliability of postal ballots, claim victory on election night before most of them were counted, and then sow enough confusion with allegations, justice department investigations and street mayhem with far-right militias to delay certification of the results.

Such a delay would create an opportunity for Republican-run state legislatures to step in and select their own electors to send to the electoral college, which formally decides who becomes president. That would produce a constitutional crisis that would ultimately be settled by the supreme court, which has a 6-3 Republican majority and has become increasingly politicised.For the plan to work it required political fealty to trump actual votes but, at several crucial decision points, that did not happen.

The key ingredient for a classic coup – a politically motivated military – was absent from the start, though not for want of Trump’s efforts. He tried to bring active duty troops on to the streets to quell the Black Lives Matter protests in the summer, but Defense Secretary Mark Esper refused to cooperate.

After Esper was fired in the wake of the election, and Trump loyalists were installed in senior decision-making positions, the chairman of the joint chiefs of staff, General Mark Milley, used a planned public appearance at the dedication of an army museum to send a pointed message.

“We take an oath to the constitution,” Milley said. “We do not take an oath to a king or a queen, a tyrant or a dictator.”

The statement was greeted with some relief – but what was most striking was that it needed to be said at all. The next lever of power that Trump tried to yank was the justice department and the FBI. The attorney general, William Barr, authorized U.S. attorneys to conduct investigations into alleged voter fraud if there are “clear and apparently-credible allegations of irregularities.”

The opening of such investigations would have supercharged conspiracy theories and given more cover for state-level Republicans to delay certification of the votes. But justice department prosecutors rebelled. The official in charge of investigating electoral crimes, Richard Pilger, resigned and others made their objections public.

“The justice department, more than most institutions, is staffed by people who have a real healthy understanding of what democracy is and why it’s worth saving,” Mulligan, now national director for national security at the Center for American Progress, said. She added that the clarity of Biden’s win made it even less likely justice department officials would go along with such a dubious enterprise.

The next line of defense was state-level Republican officials involved in the machinery of certifying results. They came under intense pressure, including in a couple of cases a direct call from the president. In some cases, notably in Michigan, they buckled, but in most states they held firm, as in the case of the Georgia secretary of state, Brad Raffensperger, who confirmed Biden’s slim majority of victory and consequently became a pariah in his own party.

“Some folks here deserve medals and some simply met an extremely low bar,” said Rebecca Ingber, a former state department legal counsel, now professor at Cardozo law school. “This is a story about guardrails working, but it’s also a reminder about the fragility of those guardrails. At the end of the day, we are talking about humans, not robots.”

Similarly, even the most conservative judges turned away the fanciful claims of election fraud pursued by the Trump legal team, whose current score in the courts is one win and 35 losses. It is possible more competent plotters could have done more damage. Trump appears to have left it until after the election to assemble a legal team, and ultimately handed control to his fiercely loyal, but erratic and hapless personal lawyer, Rudy Giuliani.

Ultimately Biden’s margin of victory – over 6 million nationwide and tens of thousands in most of the battlegrounds – was so clear, and evidence of fraud so slight, that even with better lawyers, the legal channel would have been near impossible.

But the 2020 experience has raised concerns about how US democracy would weather a closer election, and a more disciplined group determined to wield the power of the state to steal it. The militias, who were not coordinated enough to emerge as the intimidatory force Trump hoped for, could be stronger on the next occasion.

“President Trump’s rhetoric appealing to these groups has been dangerous from day one of his campaign, giving these groups tacit support for their illegal activities. And the lacklustre law enforcement response to public violence committed by these groups has exacerbated that problem,” said Michael German, a fellow at the Brennan Center for Justice and who as an FBI special agent was tasked with infiltrating extremist groups. “Their ability to organize and recruit and test tactics and networks has been strengthened. So once there is an effort to police them, they will be much more difficult a problem.”

The 2020 election has also exposed a rapidly spreading rot in the foundation of the system – public confidence that it is fair. Some 70% of Republicans, despite the clear certified results, believe the vote was rigged.

“I do think we got lucky,” said Susan Hennessey, a former lawyer at the National Security Agency and executive editor of the Lawfare blog. “The dog didn’t bark but this was not for lack of trying and had circumstances been a little bit different, and had the margin been a little bit closer, I think we have a really clear demonstration that normative constraints are not going to prevent people from taking profoundly undemocratic measures.”

Julіаn Bоrgеr

Tіа Dufоur / The White House

Help deliver the independent journalism that the world needs, make a contribution of support to The Guardian.