President Jair Bolsonaro upped his attacks on perceived enemies including the Supreme Court and the electoral system Tuesday, vowing to defend supporters' "freedom" as Brazil marked its Independence Day with rival pro- and anti-government rallies.

Throngs of Bolsonaro supporters flooded streets with the green, yellow and blue of the national flag in Brasilia, Sao Paulo, Rio de Janeiro and other cities, holding massive prayer sessions and chanting slogans in support of the embattled far-right leader.

Shouting "Get out, Bolsonaro!", opposition protesters held their own rival rallies, an opening salvo ahead of elections in October 2022 that polls currently place the president on track to lose.

Brazil's President Jair Bolsonaro (pictured September 1, 2021) is fighting record-low poll numbers and seeking to fire up his right-wing base
Brazil's President Jair Bolsonaro (pictured September 1, 2021) is fighting record-low poll numbers and seeking to fire up his right-wing base AFP / MAURO PIMENTEL

Bolsonaro, whose popularity is at an all-time low, is seeking to fire up his base in the face of a flagging economy and a series of investigations targeting him and his inner circle.

Bolsonaro, a 66-year-old former army captain who is openly nostalgic for Brazil's military dictatorship (1964-1985), warned his backers their "democracy" and "freedom" were under threat by the powers that be in Brasilia.

"As of today, we're going to start writing a new history here in Brazil," he told the rally in the capital, where he kicked the day off with a flag-raising ceremony and Air Force flyover.

People take part in a demonstration against Brazilian President Jair Bolsonaro in Rio de Janeiro
People take part in a demonstration against Brazilian President Jair Bolsonaro in Rio de Janeiro AFP / DOUGLAS SHINEIDR

With hardline backers urging a military intervention to give Bolsonaro unfettered power, there had been fears the day could turn violent, with echoes of the January 6 attack on the US Capitol by supporters of former president Donald Trump -- to whom Bolsonaro is often compared.

Police reported few incidents, though Bolsonaro supporters harassed journalists covering the rallies in Brasilia and Sao Paulo, and tore down a police barricade in the capital Monday night.

Brazil's President Jair Bolsonaro, seen here in Brasilia, is fighting record low poll numbers and seeking to fire up his right-wing base
Brazil's President Jair Bolsonaro, seen here in Brasilia, is fighting record low poll numbers and seeking to fire up his right-wing base AFP / EVARISTO SA

Bolsonaro doubled down on his attacks on Brazil's electronic voting system, telling a massive crowd in Sao Paulo he refused to take part in an election "farce" in 2022.

"We want clean, democratic elections... I can't participate in a farce like the one being sponsored by the Superior Electoral Tribunal," he said.

A supporter of Brazilian President Jair Bolsonaro holds a t-shirt during the launch of Bolsonaro's new party, the Alliance for Brazil, at a hotel in Brasilia
A supporter of Brazilian President Jair Bolsonaro holds a t-shirt during the launch of Bolsonaro's new party, the Alliance for Brazil, at a hotel in Brasilia AFP / EVARISTO SA

"Only God can remove me. I'm only coming out of this jailed, dead or victorious."

Bolsonaro has repeatedly attacked Brazil's voting system, claiming -- without evidence -- that it is plagued by fraud.

He wants a paper copy of each ballot printed to enable an audit.

A man holds a banner that reads "Bolsonaro thief, impeachment is the solution" during a demonstration against Brazilian President Jair Bolsonaro in Rio de Janeiro
A man holds a banner that reads "Bolsonaro thief, impeachment is the solution" during a demonstration against Brazilian President Jair Bolsonaro in Rio de Janeiro AFP / DOUGLAS SHINEIDR

Electoral authorities say the system, introduced in Brazil in 1996, is sound, and that adding paper print-outs would only introduce a potential avenue for fraud.

Bolsonaro also renewed his attacks on the Supreme Court, which has notably ordered an investigation of him and his inner circle over allegations of systematically spreading fake news from within the government.

The president additionally faces a Senate inquiry into his government's controversial handling of Covid-19, which has claimed more than 580,000 lives in Brazil, second only to the United States.

The biggest rally was in Sao Paulo, where Bolsonaro supporters turned the Avenida Paulista into a sea of green and yellow.

Sao Paulo public security officials estimated the turnout at 140,000 people for the pro-Bolsonaro rally and 15,000 for the anti-Bolsonaro demo several kilometers (miles) away.

"We're here telling the president and the armed forces yes, we want them to stage an intervention. They're the only ones protecting our freedom," said pro-Bolsonaro metal worker Valdivino Pereira, 52.

Sao Paulo health authorities said they had fined Bolsonaro for the seventh time for failing to wear a face mask, violating coronavirus containment measures.

Recent polls put Bolsonaro's approval rating at less than 25 percent, the lowest level since he took office in 2019.

With polls putting him on track to lose badly to leftist ex-leader Luiz Inacio Lula da Silva in next year's elections, Bolsonaro is hoping to use the rally to energize his supporters.

Political scientist Mauricio Santoro said he feared Bolsonaro would try to follow the same script as Trump and attempt to delegitimize Brazil's elections.

"This is the first time since the end of Brazil's military dictatorship (in 1985) that we have a president making speeches against democratic institutions," he told AFP.

"It looks like a dress rehearsal for what Bolsonaro could do in 2022."