As President Jair Bolsonaro lays the groundwork to contest a potential defeat in an October election, Brazil's courts, congressional leadership, business groups and civil society are closing ranks to shore up trust in the integrity of the vote.
Even leaders of the armed forces, now more entwined in government than at any point since a 1964-1985 military dictatorship, offer private assurances to former peers that they want no part in disrupting democratic order, according to a half dozen former officials with close ties to military leadership.
The result is a far-right populist firebrand trailing in the polls with few institutional levers to derail the electoral process – but enough hardcore supporters to fill the streets with angry demonstrations if he cries foul as many expect.
"One thing is certain about this election: President Bolsonaro will only accept one result – victory. Any other result will be contested," said Camilo Caldas, a constitutional law professor at St. Jude University in Sao Paulo.
When pressed in interviews, Bolsonaro says he will respect the election result as long as voting is "clean and transparent," without defining any criteria.
Many believe that leaves room for turbulence after the vote. Electoral officials warn of an uprising inspired by the invasion of the U.S. Capitol in Washington last year if Bolsonaro loses to leftist former President Luiz Inacio Lula da Silva, as polls suggest.
For more than a year, Bolsonaro has insisted to his base without evidence that the polls are lying, Brazil's electronic voting system is open to tampering, and Supreme Court justices overseeing elections could rig the vote in Lula's favor.
Even one of Bolsonaro's campaign advisers, who requested anonymity to speak freely, could not rule out violent post-election demonstrations if the president challenges the results: "Bolsonaro is absolutely unpredictable. There could be trouble."
Bolsonaro has shown he can easily mobilize tens of thousands of supporters, as he did at Independence Day rallies this month. Demonstrators cited the big crowds as evidence that opinion polls are skewed and electoral fraud is Lula's only hope.
"If Lula wins, you can be sure there was major fraud and people will be really upset," said retired naval captain Wilson Lima, an organizer of the Bolsonaro rally in Brasilia. "An angry population will run amok. God knows what can happen."
Determined to avoid that, major Brazilian institutions have spent the past year trying to get ahead of Bolsonaro.
Congress voted down his push for a return to paper ballots. Election officials created a "transparency commission" with tech experts, civic groups and government organs to review security measures and endorse best election practices. A record number of foreign observers are coming to monitor the vote.
Business leaders have also penned public declarations of their faith in the electoral system. Supreme Court Justice Jose Antonio Dias Toffoli told journalists in Sao Paulo that the business community understood a break with democracy would be "economic suicide," given the risk of sanctions from Europe and other Western powers.
Allies such as the United States have also signaled both publicly and privately what they expect from the second-largest democracy in the Western Hemisphere.
The director of the U.S. Central Intelligence Agency, Bill Burns, last year told Bolsonaro's senior aides that he should stop casting doubt on Brazil's electronic voting system, Reuters reported in May.
International election experts have praised Brazil's electronic voting machines for ending widespread fraud in the tabulation of paper ballots before 1996, with no cases of fraud detected since then despite Bolsonaro's accusations.
TRUMP PLAYBOOK
The issue has unsettled many in Washington who see Bolsonaro following in the steps of former President Donald Trump, whose baseless allegations of fraud in the 2020 U.S. election were echoed by the Brazilian leader even after the Capitol invasion.
Bolsonaro was one of the last world leaders to recognize President Joe Biden's electoral victory. The Brazilian president has warned that the aftermath of Brazil's election this year could be worse than the fallout from that contested U.S. vote.
However, while Trump was able to unleash a blitz of lawsuits and political pressure on elected officials responsible for counting votes, voting in Brazil is run by federal electoral courts whose judges show no qualms about standing up to Bolsonaro.
In particular, Bolsonaro's attacks on the Supreme Electoral Tribunal (TSE) and its head, Supreme Court Justice Alexandre Moraes, seem to have only steeled the resolve of the judge and his colleagues.
Even as Moraes has acted more unilaterally than some of his predecessors, he enjoys ample backing among fellow Supreme Court judges, according to two people familiar with the institution.
Bolsonaro has hurled abuse at Moraes for overseeing an investigation of his supporters, who allegedly spread libel and misinformation online. Last year, he called Moraes a "crook" and briefly refused to obey the judge's rulings.
In Brasilia's corridors of power, however, uneasiness over the judge's hardball tactics has taken a back seat as his peers and most politicians present a united front in defense of the courts and the electoral process.
When Moraes took the reins of the TSE last month, his speech praising the electronic voting system was met with a standing ovation from an audience that included four former presidents, some 20 current state governors and an array of party leaders. Bolsonaro looked on sternly without applauding.
MILITARY IN SPOTLIGHT
Even the army officials tasked by Bolsonaro with digging into the alleged vulnerabilities of Brazil's voting system have been pleased with the openness of Moraes to their requests since he took over the TSE, according to a senior military officer, who declined to be named due to military protocol.
Invited by the TSE to join its transparency commission, Brazil's armed forces have taken an unprecedented role in probing the security of the country's voting system.
Critics question the military's prominence in the process, especially as its concerns have echoed Bolsonaro's rhetoric about potential fraud. The president, a former army captain, has packed his cabinet with former military officers, while telling rallying supporters that the armed forces are "on our side."
However, the armed forces seem to have stopped short of setting up a "parallel count" on election night as Bolsonaro has suggested. Instead, military representatives plan to make spot checks of voting machines, comparing the paper readouts at a few hundred voting stations with the results sent to the TSE server.
It is an unusual task for the armed forces in Brazil's young democracy, but military brass insist it is not a sign of political ambitions.
Former Defense Minister Raul Jungmann ruled out any risk of a coup, contrasting the country today with Brazil in 1964: the military takeover that year was openly supported by many of Brazil's business elites, middle class families, churches and mainstream media – a far cry from the current environment.
"There is no way military commanders will risk getting involved in an adventure," said a seasoned politician in regular conversation with military chiefs.
(Reporting by Anthony Boadle and Ricardo Brito; Additional reporting by Lisandra Paraguassu; Editing by Brad Haynes and Ross Colvin)