(Adds number of injured, Temer statement on troops, allied party standing with him for now, analyst sees more protests to come)
By Alonso Soto and Anthony Boadle
BRASILIA, May 24 (Reuters) - Protesters demanding the resignation of Brazilian President Michel Temer staged running battles with police and set fire to a ministry building in Brasilia on Wednesday, prompting the scandal-hit leader to order the army onto the streets.
Police unleashed volleys of tear gas, stun grenades and rubber bullets to halt tens of thousands of protesters as they marched towards Congress to call for Temer's ouster and an end to his austerity program.
Masked protesters fired powerful fireworks at police, set ablaze furniture in the Agriculture Ministry, and sprayed anti-Temer graffiti on government buildings.
It was the most violent protest in Brasilia since anti-government demonstrations in 2013 and fueled a political crisis sparked by allegations Temer condoned paying off a potential witness in a massive corruption probe.
The scandal has raised chances Brazil could see a second president fall in less than a year.
Police cordons held back protesters from advancing on the modernistic Congress building where the main ally in Temer's coalition, the PSDB party, met to discuss whether to continue backing him and prepare for a post-Temer transition.
One protestor was shot and wounded, police said. Local media reported at least one other demonstrator was seriously injured by a rubber bullet to the face, while another lost part of his hand while trying to throw an explosive device at officers. The city government said 49 people were hurt.
Temer approved a decree allowing army troops to assist police in restoring order in Brasilia for the next week, giving soldiers policing powers and the right to make arrests. His office said Temer turned to the military after police were overwhelmed.
The move brought immediate criticism in a nation where memories of a brutal 1964-85 military dictatorship remain fresh.
"What are they going to do? Intervene and wage war against the people that are out there on the esplanade?" Senator Gleisi Hoffmann of the opposition Workers' Party said on the Senate floor.
Temer, a former vice president whose government's approval rating is in the single digits, took office a year ago after former President Dilma Rousseff was impeached for breaking budgetary laws.
Rousseff and her supporters labeled that a "coup" orchestrated by Temer and his allies in an effort to halt a sweeping, three-year corruption probe that has placed scores of sitting politicians under investigation.
Temer defiantly refused to resign last week after the Supreme Court opened an investigation into the hush-money allegations made in plea-bargain testimony by executives at meatpacking giant JBS SA.
The accusations pummelled Brazilian financial markets on doubts Congress would pass government austerity measures meant to pull Brazil out of its worst-ever recession
Temer could be removed from office by Brazil's top electoral court which meets on June 6 to decide whether to annul the 2014 election victory by the Rousseff-Temer ticket for using illegal money to fund their campaign.
If that happens, Congress would have 30 days to pick a successor to lead Brazil until elections late next year.
The parties of Temer's main allies are split over whether to quit his coalition immediately or first agree on a consensus figure to replace him and save his reform agenda. The market-friendly measures are considered vital to restore business credibility and investment needed to end a two-year recession.
The PSDB, Brazil's third largest party, announced it was staying in the government for now to make sure an orderly transition was in place if Temer has to go, party leader, Senator Tasso Jereissati, told reporters after meeting with lawmakers.
Outside, the message demonstrators chanted was clear: "Out with Temer!, general election now!"
Sonia Fleury, a political analyst at think tank FGV, said more violent protests can be expected in a country where discontent with a discredited political establishment is rife.
"We are in a very deep crisis. Temer is no longer governing. Anything he does, like call out soldiers, can only make things worse," she said.
Unions were galvanized by opposition to a bill that would cut their power in the workplace by allowing temporary non-unionized contracts and ending obligatory payment of union dues.
"Temer can't stay and these reforms that trample on our rights cannot advance. We want elections now," said Dorivaldo Fernandes, 56, member of a health workers union in the neighboring state of Goias.
Leftist senators, who on Tuesday succeeded in obstructing discussion of the labor reform bill, read out a constitutional amendment in committee that would allow early general elections instead of waiting until October 2018.
But chances of changing the constitution in the midst of a political crisis were minimal. (Reporting by Alonso Soto and Anthony Boadle; Additional reporting by Maria Carolina Marcello in Brasilia and Brad Brooks in Sao Paulo; Writing by Anthony Boadle and Brad Brooks; Editing by Marguerita Choy and Andrew Hay)