Sergio Moro, Brazil's justice and security minister, resigned on Friday after clashing with President Jair Bolsonaro over the sacking of the federal police chief.

Moro, a former anti-corruption judge, hit out at "political interference" with the federal police, saying he could not do his job without "autonomy" for the force.

The news sparked jitters in the markets with Sao Paulo's stock exchange, the largest in Latin America, closing down nearly 5.5 percent and the real dropping to a record low of 5.7 against the US dollar.

"I'm going to start packing up my things and send my resignation letter," said Moro, 47, during a long speech in the capital Brasilia in which he accused the far-right Bolsonaro of "breaking the promise of a carte blanche."

Bolsonaro hit back at Moro, accusing him of being motivated by "ego" and making "unfounded accusations."

The president claimed he had told several lawmakers before Moro announced his resignation: "Today you will see a person who is committed to himself, to his ego, but not to Brazil."

Moro's resignation came after Bolsonaro sacked federal police chief Mauricio Valeixo, a close Moro ally. The president replaced him with Alexandre Ramagem, chief of the Brazilian Intelligence Agency.

"The change at the head of the federal police without a genuine reason is political interference that harms my credibility and that of the government," said Moro.

Moro said Bolsonaro had told him he was replacing Valeixo for someone with whom he had "personal contact, whom he could call, ask for information, intelligence reports."

"Providing this type of information is not the job of the federal police," he added, insisting on independence for investigations.

Moro alleged Bolsonaro had said one of the reasons he wanted to replace Valeixo was that he was "worried" about some ongoing investigations.

Bolsonaro's decision to sack Valeixo against Moro's advice was "a signal that the president wanted me out," said Moro.

But Moro hit back, saying his ally's position "was never used as currency in exchange for me being named to" the top court.

Sylvio Costa, founder of political website Congresso em Foco, said the president's move was about self-preservation.

"Bolsonaro wants to protect himself. It's the federal police that's investigating various suspected crimes haunting the president, his family and allies," said Costa.

Moro made his name as a judge in leading the high-profile Car Wash corruption investigation that notably saw former leftist president Luiz Inacio Lula da Silva jailed for accepting a bribe.

He began investigating leading political figures under a left-wing government in 2014 but said even then he'd never before faced such political interference.

Analysts say Moro's departure crowns a "politicization" process of governmental organs battling corruption despite Bolsonaro insisting during his 2018 election campaign that he would provide transparency and honesty.

"Since he assumed the government (in January 2019), Bolsonaro has tried to intervene in a series of anti-corruption organizations with the aim of increasing his control over future investigations," said Thomaz Favaro, an analyst for Control Risks consultancy.

Favaro pointed to Bolsonaro's choice of Augusto Aras as attorney general, despite his omission from a list put together by Brazilian prosecutors.

Picking from that list was a tradition that had been respected since at least 2003.

"Moro's resignation is a seismic event in Brazilian politics," said Ilona Szabo, executive director of the investigative Igarape Institute.

"His departure signals a dangerous new phase for Brazil. It amounts to a 'coup' against democracy because the autonomy of the federal police (and rule of law) is an essential foundation for democratic governance."

Last week, Bolsonaro fired his health minister, Luiz Henrique Mandetta, who supported isolation as a tool to contain the spread of the new coronavirus. Bolsonaro has repeatedly downplayed the danger of COVID-19.

"Mandetta's vision was that of health, of life. Mine is more than life, it includes the economy and jobs," Bolsonaro said at the time.