Brazil's president ordered soldiers to restore order in the country's capital Wednesday after some government ministries were evacuated during clashes between police and protesters who are seeking the leader's ouster.

Tens of thousands of demonstrators marched to Congress to protest economic reforms that President Michel Temer is pushing through and to demand he step down amid a corruption scandal.

Scuffles between police and protesters who tried to jump a cordon mushroomed into a series of clashes in which officers fired tear gas and pepper spray to contain the crowd. Protesters set fires and used portable toilets as barricades.

Story continues below advertisement

Local media captured video images of military police firing pistols into the air. The Secretariat of Public Security issued a statement late Wednesday saying it would investigate the weapons firing, saying that "this procedure is not used in protests." Earlier, it said one person had been injured by a bullet but give no information on who fired the shot.

A fire broke out in the Ministry of Agriculture, and demonstrators smashed windows and doors at other ministries. Some government agencies were evacuated in response, the president's office said.

In a brief national address during the unrest, Defence Minister Raul Jungmann said troops were being sent to guard federal buildings, including the presidential palace. The weeklong deployment was authorized by a presidential decree which left open the possibility that soldiers could be used more widely in Brasilia. The decree said Jungmann would decide the scope.

"This mess, this mayhem is unacceptable," Jungmann said. "President Temer will not allow that."

Jungmann added that soldiers had already entered the Foreign Ministry, and televised images showed troops outside the presidential palace. In all, 1,500 will be deployed, the Defence Ministry said.

Temer is struggling to retain power after the release of a recording that appears to capture him approving hush money for a convicted former lawmaker. Brazil's top court is investigating him for alleged obstruction of justice and involvement in passive corruption. The president has denied wrongdoing and said he will not resign.

His unusual decision to call in the military could heighten anger against the government if it is seen as the last gasp of a president trying to maintain his hold on power.

Story continues below advertisement

"This decree was never used in this context to protect an administration that is politically isolated," said Newton de Oliveira, a professor and security specialist at Mackenzie University in Rio de Janeiro. He said he thought the supreme court might be called on to evaluate whether the move was constitutional.

Late Wednesday, Temer's office issued a statement saying the move was necessary after violence had put the lives and safety of public servants at risk. It said the president had determined that using the country's National Force, an elite police entity, would not have been sufficient. He also denied the move was unusual, it said.

"When order is re-established, the decree will be revoked," the statement said. "The president of the republic underscores that he will not hesitate to exercise the authority given to his office whenever it is necessary."

Already, many Brazilians see Temer as illegitimate because he came to office after his predecessor, Dilma Rousseff, was impeached and removed. His popularly only plummeted once he began governing as he tried to pass economic changes meant to jump start the economy, which is in a deep and protracted recession. A series of corruption allegations that have swirled around him and his administration also disillusioned voters.

Now, with the latest allegations against Temer himself, many Brazilians have had enough.

In the wake of the announcement on the use of the military, senior officials began distancing themselves from the decision.

Story continues below advertisement

"If this government cannot hold itself up, the armed forces will not hold up this government," said Sen. Renan Calheiros, who is the whip for Temer's party in the upper house but has increasingly challenged the president.

Rodrigo Maia, the speaker of the lower house of Congress, who had asked Temer to instead use the National Force, called the move "an excess" and said he hoped it wouldn't last longer than a day.

Sen. Romero Juca, a Temer ally, defended the president's decision, saying: "President Temer brought in the armed forces because a bunch of criminals were setting ministries on fire."

The pressure on Temer to resign continued to ratchet up Wednesday. Federal police asked the president to submit to questioning, his defence team said in a statement, but a supreme court justice later determined the police did not have the right to do that.

Temer also lost yet another aide when Sandro Mabel resigned Wednesday, saying he needs to spend more time with his family. He is the latest in a string of aides and allies who have resigned or been fired amid corruption allegations.

With Brazil deeply divided and a political crisis deepening, a session of the lower house of Congress became chaotic, with opposition politicians surrounding the speaker's desk in protest and holding signs saying Congress' workings should be transparent. The Senate's session also descended into chaos.

Story continues below advertisement

Several lawmakers have submitted requests for Temer's impeachment to the speaker and Maia has angered them by saying he would take his time to review the requests.

While Congress debated, 35,000 people were marching toward the chamber down a long avenue lined with the main government buildings, including the Supreme Court, the presidential palace and the ministries.

Protesters shouted "Out with Temer!" and carried signs calling for immediate direct presidential elections.

If Temer resigned, the Constitution says Congress would elect the next president, who would hold power for the rest of his term, which runs to the end of 2018. But many Brazilians, disgusted with the political class, want to vote themselves.

Protests in Rio de Janeiro against Temer and state austerity measures also descended into chaos, with demonstrators clashing with police.