RIO DE JANEIRO — Brazilian Justice Minister Sérgio Moro, who shepherded the sprawling corruption probe that imprisoned some of Latin America's most influential people, resigned in protest Friday after President Jair Bolsonaro fired his police chief.

In an extraordinary resignation speech, Moro charged that Bolsonaro was trying to improperly politicize the Justice Ministry. The move sent political shock waves through Latin America’s largest country as it grapples with the worst public health crisis in a lifetime.

Moro said he could discern only political and improper motives behind Bolsonaro’s decision to fire Maurício Valeixo, the head of the federal police. He accused Bolsonaro of wanting to install a police chief who would grant him access to confidential reports and take investigative requests, jeopardizing the agency’s political independence.

“That really isn’t the role of the federal police to serve this kind of information,” Moro said.

The political drama rapidly evolved throughout Friday. The Brazilian attorney general called for an inquiry into the accusations. Then Bolsonaro denied any misconduct in a lengthy and unfocused speech. And finally, a nightly news program aired messages leaked by Moro that appeared to undercut Bolsonaro’s rebuttals.

Bolsonaro had said he hadn’t tried to interfere with the federal police, but WhatsApp messages aired by the news show National Journal appeared to show Bolsonaro urging the removal of Valeixo because of investigations into his supporters. “Another reason for the removal,” Bolsonaro allegedly said on Thursday in a message to Moro.

Brazilian attorney general Augusto Aras said Moro’s allegations, if true, “would reveal the practice of illegal actions.”

The resignation deprived Bolsonaro of one of his most crucial and popular allies, further isolating him as he comes under criticism for his handling of the coronavirus crisis.

It also illustrated how quickly the political landscape has shifted in Brazil since the arrival of the pandemic.

Bolsonaro has repeatedly minimized the disease, calling it “a little flu” that doesn’t warrant closing businesses, shuttering schools and national isolation. His positioning — which he’s maintained even with more than 3,400 dead and 51,000 infected — has put him at odds with many of his political allies and most of the Brazilian population.

Governors who once supported him have called his behavior reckless. Angry Brazilians are banging pots outside their windows and calling for his removal.

And in perhaps the biggest political blow, the country’s hugely popular health minister, Luiz Henrique Mandetta — whose sober, technocratic daily news conferences calmed many anxious Brazilians — was fired by Bolsonaro last week after he repeatedly and publicly contradicted the president on the severity of the crisis.

Meanwhile, investigators are pursuing corruption investigations into those closest to Bolsonaro, including his son Flavio, a federal senator.

“He’s been weakened by his handling of the pandemic,” said Matias Spektor, an associate ­professor of international relations at Fundação Getúlio Vargas in São Paulo. “He has lost a significant amount of support, and he feels it. He feels the investigations closing in on ­family members. So he has sacked the head of the military police, and he’s not in a good place.”

To many here, Moro has been less a cabinet member than a national icon. At political rallies, his features have been super­imposed onto giant Superman ­balloons. At supermarkets, he has been cheered. In a country perennially hobbled by corruption, he was a figure who for many represented a new, better Brazil.

His legend was cultivated while he was a judge, overseeing the Lava Jato corruption probe. It led to the convictions of some of Latin America’s most powerful political figures, including former Brazilian president Luiz Inácio Lula da Silva. The removal of Lula, who had been leading in the presidential opinion polls, effectively cleared the path for Bolsonaro to the presidency. Bolsonaro then appointed Moro as his justice minister.

Moro’s resignation and remarks Friday are sure to inflame fears of authoritarian tendencies in Bolsonaro, a former army officer who rose to power lamenting the collapse of Brazil’s military dictatorship and, just days ago, joined a rally in Brasília where protesters called for its return.

In a freewheeling national address late Friday afternoon, Bolsonaro denied he had acted improperly. He said that he didn’t need anyone’s permission to fire someone — and that he had never asked the federal police to protect him from investigations. Moro’s allegations, he said, had left him heartsick.

“I always opened my heart to him,” Bolsonaro said. “And I doubt if he ever opened his for me.”

Moro said he explained to Bolsonaro that his removal of the police chief, who was overseeing the investigations into his family, would be seen as improper. “There was this insistence from the president,” he said. “I told him that this would be political interference, and he said that it would be.”

Opposition lawmakers immediately seized on the comments — and called on Moro to testify publicly.

“Moro imploded the Bolsonaro government,” Marcelo Freixo, an opposition lawmaker, wrote on Twitter. “It affirmed that the president wants to control the police to grant criminal impunity to his family and to attack democracy.”

Heloísa Traiano contributed to this report.