(Bloomberg) -- Former Brazil President Jair Bolsonaro praised Elon Musk as a free-speech advocate, in his latest effort to build opposition to the country’s Supreme Court as his legal troubles mount. 

Bolsonaro and his supporters painted the court as overzealous and anti-democratic at a rally in Rio de Janeiro on Sunday as they railed against Judge Alexandre de Moraes, who is overseeing investigations into Bolsonaro and the spread of disinformation.

Musk, the owner of the social-media platform X, pledged earlier this month to defy the court and reinstate user accounts that had been banned as part of its efforts to combat the spread of fake news online. The company later said it would continue to comply.

Read more: Brazil’s Top Justice Opens Criminal Inquiry Against Elon Musk

Bolsonaro and Musk contend the court is overstepping its authority in a way that’s undermining free speech. The court argues that battling online disinformation is crucial to democracy.

Musk is “a man that had the courage to show with some evidence, and with more to come, where our democracy was heading, and how much freedom we have already lost,” Bolsonaro told supporters. “I respectfully ask for a round of applause for Elon Musk.”

Right-wing deputy and Bolsonaro supporter Gustavo Gayer spoke in English during the demonstration, calling out Musk. “I will speak in English because I am certain that Musk is watching what is happening here right now,” Gayer said.

The demonstration, much like a February rally that drew hundreds of thousands of supporters to the streets of Sao Paulo, also aimed to blunt momentum behind an investigation into allegations that Bolsonaro planned a coup attempt after his 2022 election defeat, said Silas Malafaia, a prominent evangelical pastor who helped organize the event. During Sunday’s rally, Malafaia continued to claim that Judge Moraes is “a threat to democracy.”

Read More: Bolsonaro Targeted as Police Ensnares Alleged Coup Plotters

The probe into the alleged coup plot is one of several major legal investigations facing the right-wing former leader. Police have targeted dozens of his allies as part of investigations into the events of Jan. 8, 2023, when thousands of Bolsonaro supporters stormed major government buildings in the nation’s capital in response to his election loss. Bolsonaro has denied wrongdoing.

Read More: Musk Meets His Match in Brazil’s Fake News-Fighting Top Court

The event served as an opportunity for Bolsonaro to re-energize his right-wing base ahead of October municipal elections in which his Liberal Party wants to continue building on its recent success. Along with its allies, the party is targeting 1,000 victories in mayoral races — roughly 20% of those up for grabs — as it seeks to set the stage for a 2026 challenge to President Luiz Inacio Lula da Silva.

“If something bad happens to me, don’t lose hope, keep on fighting,” Bolsonaro said.

©2024 Bloomberg L.P.