Brazil will hold the most polarised presidential election in decades next month, with many expecting incumbent president Jair Bolsonaro to contest the result if he is defeated by former leftist president Luiz Inacio Lula da Silva, as polls suggest.
Electronic voting
Brazil adopted electronic voting machines in 1996 to end widespread fraud involving paper ballots. After winning political office in a dozen elections using the current voting system, Mr Bolsonaro ramped up his criticism last year as opinion surveys showed him on track to lose re-election.
He has repeatedly asserted that the machines are open to tampering, but he has produced no evidence of fraud.
He has also attacked the Supreme Court justices sitting on the Supreme Electoral Tribunal (TSE) for defending the electronic system and claimed they could rig it to favour of Mr Lula.
International voting experts and electoral officials say the technology is secure, with no cases of fraud detected.
Thin paper trail
Still, some election experts say the lack of a paper record for each vote does limit opportunities to conduct audits if the election is contested.
Voters punch their choices into electronic voting machines at 477,000 voting stations across Brazil. A paper receipt of each machine's total is signed by officials and displayed publicly in each polling place.
The digital results of each machine are put on pen drives and sent via secure connection for centralised tabulation at TSE headquarters in Brasilia.
Last year, Congress voted down Mr Bolsonaro's proposal to reintroduce a paper record for each vote cast.
Trump model
Some of Mr Bolsonaro's supporters last year tried to occupy the Supreme Court, inspired by the 2021 assault on the US Capitol by backers of former president Donald Trump.
Mr Bolsonaro echoed Mr Trump's baseless fraud claims after the 2020 US election, and he was one of the last world leaders to recognise president Joe Biden's victory.
Many observers worry Mr Bolsonaro could take a similar approach if he loses next month.
'My army'
Mr Bolsonaro, a former army captain, has added to institutional tensions by blurring the lines between his government and the armed forces. He has referred to the military as "my army" and told rallying supporters it is "on our side."
Mr Bolsonaro has also handed out a record number of jobs to current and former military officers in his government, including key roles in his cabinet.
However, leaders of the armed forces 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.
Political and defence analysts largely agree that Brazil's military lost its appetite for politics after the 1964-1985 dictatorship that eroded the prestige of the armed forces.
Unlike the 1964 military takeover, Brazil's business elites, churches and mainstream media are not calling for political intervention by the armed forces.
Foreign observers
Bracing for trouble, electoral authorities have invited a record number foreign organisations to send observer missions and vouch for the integrity of the elections.
For the first time, two US-based organisations, the International Foundation for Electoral Systems (IFES), a non-partisan, non-profit group, and the Carter Center, a non-profit set up by former president Jimmy Carter, are sending missions to observe Brazil's elections.
The Carter Center said its electoral expert mission would assess the transparency and functioning of the electronic voting system but would not inspect the technology nor provide an overall assessment of the counting processes.
The TSE also invited the European Union to send election observers, but the Bolsonaro government vetoed the proposal.