Musk, the owner of X and a self-declared free speech absolutist, has challenged a decision by Justice Alexandre de Moraes ordering the blocking of certain accounts. He has said X, formerly known as Twitter, would lift all the restrictions because they were unconstitutional and called on Moraes to resign.
Neither Musk, X nor Brazilian authorities have disclosed which social media accounts were ordered blocked. X first posted about the order to block on Saturday but it was not immediately clear when the order was issued.
Moraes is investigating "digital militias" that have been accused of spreading fake news and hate messages during the government of former far-right President Jair Bolsonaro and is also leading an investigation into an alleged coup attempt by Bolsonaro.
Musk, in an X post, accused Moraes of "brazenly and repeatedly" betraying the constitution and people of Brazil.
"This judge has applied massive fines, threatened to arrest our employees and cut off access to X in Brazil," he said in the post.
"As a result, we will probably lose all revenue in Brazil and have to shut down our office there. But principles matter more than profit."
The billionaire has pledged to legally challenge the order blocking X accounts where possible.
Moraes responded by adding Musk to the investigation he is leading into fake news on social media, and opening an inquiry into what he called an obstruction of justice.
In his decision, Moraes said: "X shall refrain from disobeying any court order already issued, including performing any profile reactivation that has been blocked by this Supreme Court."
If X fails to comply with the order to block certain accounts the company will be fined 100,000 reais ($A30,041) per day, the judge said in a statement released to media.
President Luiz Inacio Lula da Silva's leftist government expressed support for Moraes, with Solicitor General Jorge Messias criticising Musk and calling for the regulation of social media networks to prevent foreign platforms from violating Brazilian laws.
"We cannot live in a society in which billionaires domiciled abroad have control of social networks and put themselves in a position to violate the rule of law, failing to comply with court orders and threatening our authorities," Messias said in a post on X.
Last year, Moraes also ordered an investigation into executives at social messaging platform Telegram and Alphabet's Google, who were in charge of a campaign criticising a proposed internet regulation bill.
The bill puts the onus on internet companies, search engines and social messaging services to find and report illegal material, instead of leaving it to the courts. It would also impose hefty fines for failures to do so.