Arch-conservative Bolsonaro denounced the judge who ordered the suspension of X, the former Twitter which is popular among Brazil's conservatives, as a "dictator."
"We must put a stop to those who exceed the limits of our constitution," he told the sea of protesters clad in the yellow and green colors of the Brazilian flag, referring to Supreme Court justice Alexandre de Moraes.
The demonstration in Sao Paulo took place on Brazil's Independence Day, in counter-programming to a military parade in the capital Brasilia overseen by leftist President Luiz Inacio Lula da Silva.
In Sao Paulo, Latin America's largest city, posters and banners called for "democracy" and "liberty," as well as the ouster of Moraes, who ordered X blocked in Brazil a week ago.
The move was the culmination of a legal spat that began when Moraes ordered the suspension of several X accounts belonging to Bolsonaro supporters.
"I'm here to demand the removal of Alexandre de Moraes; what he is doing is unacceptable," 35-year-old architect Emilia Lapolli told AFP. "He's ignoring the constitution and making laws as he pleases."
"I want to protest against the madness taking place in our country. We're being subjected to censorship," said one demonstrator, retired computer engineer Sergio Luiz Barreira.
One of the rally's organizers, evangelical pastor Silas Malafaia, declared that Moraes "must be impeached and go to jail! Criminals belong in jail!"
Bolsonaro, 69, stopped briefly at a hospital in the morning due to a "bad flu," his aides said, while adding that it would not keep him from appearing at the rally.
He clearly hoped to use the march to demonstrate his political clout a month before municipal elections in the deeply divided country.
The rally attracted about 45,000 people, according to researchers at the University of Sao Paulo.
- Disinformation -
Bolsonaro left office nearly two years ago after a razor-thin election defeat to archrival Lula.
That prompted so-called Bolsonaristas to storm the presidential palace, Congress and Supreme Court on January 8, 2023, calling for the military to oust Lula and claiming, without evidence, that the election was stolen.
Bolsonaro, dubbed the "Tropical Trump," is under investigation for an alleged coup attempt over those events.
Bolsonaro and the far right are at war with Moraes, who presided over the TSE electoral tribunal when it banned the ex-president from running for office until 2030 over his attempts to discredit Brazil's electoral system.
Moraes, who has taken on the mantle of an anti-disinformation crusader, is also leading several other investigations into Bolsonaro.
Lula, for his part, has come out in support of the fight against "fake news."
"We will always be intolerant of any person, regardless how rich, who defies Brazilian law," the president said Friday.
Members of the right-wing opposition in Brazil's Senate have said they will file for Moraes's impeachment next week -- a move welcomed by X's billionaire owner Elon Musk.
Bolsonaro has traveled the country widely in recent months to boost allies who will be seeking office in October local elections.
In Brasilia, Lula -- with Moraes seated near him on the official podium -- presided over a parade featuring 30 military athletes who competed in the Paris Olympic Games.
Before taking his seat, Lula waved as he rode through town in the presidential Rolls-Royce.