BRASILIA, April 18 (Reuters) - Brazil's leftist President Dilma Rousseff suffered a humiliating loss when the lower house of Congress voted to impeach her on Sunday, leaving her almost certain to be forced from office months before the nation hosts the Olympics.
Fireworks lit up the night sky in Brazil's megacities of Sao Paulo and Rio de Janeiro after the opposition comfortably surpassed the two-thirds majority needed to send Rousseff for trial in the Senate on charges of manipulating budget accounts.
The floor of the lower house was a sea of Brazilian flags and pumping fists as dozens of lawmakers carried in their arms the deputy who cast the decisive 342nd vote, after three days of a marathon debate.
The final tally was 367 votes cast in favor of impeachment, versus 137 against, and seven abstentions. Two lawmakers did not show up to vote.
Brazilian financial markets opened higher after the vote - which was a major step toward ending 13 years of the left-leaning Workers' Party rule in the world's ninth largest economy.
The central bank intervened against a sharp rise in the currency, offering up to $4 billion in derivatives at an auction. The real traded 3.53 per dollar, while yields on rate futures fell and equity futures rose.
If, as is expected, the Senate votes by a simple majority in early May to proceed with the impeachment, Rousseff would be suspended from her post and replaced by Vice President Michel Temer as acting president, pending her trial. Temer would serve out Rousseff's term until 2018 if she is found guilty.
The impeachment battle, waged during Brazil's worst recession since the 1930s, has divided the country of 200 million people more deeply than at any time since the end of its military dictatorship in 1985.
It has also sparked a bitter battle between the 68-year-old Rousseff and Temer, 75, that could destabilize any future government and plunge Brazil into months of uncertainty.
Despite anger at rising unemployment, Rousseff's Workers Party can still rely on support among millions of working-class Brazilians, who credit its welfare programs with pulling their families out of poverty during the past decade.
"The fight is going to continue now in the streets and in the federal Senate," said Jose Guimaraes, the leader of the Workers' Party in the lower house. "We lost because the coup-mongers were stronger."
Opinion polls suggest more than 60 percent of Brazilians support impeaching Rousseff, Brazil's first female president, less than two years after she won reelection in 2014.
While she has not been accused of corruption, Rousseff's government has been tainted by a vast graft scandal at state oil company Petrobras and by the economic recession.
Hundreds of thousands of demonstrators from both sides took to the streets of towns and cities across Brazil on Sunday, in peaceful protests. Millions watched the congressional vote live on television in bars and restaurants, in their homes or on giant screens in the street, as the soccer-mad nation does for major football matches.
On the grassy esplanade outside Congress, a 6-foot-high (2-meter) security barrier ran for more than half a mile (1 km) to separate rival demonstrations, a symbol of the political rift that has emerged in one of the world's most unequal societies.
The impeachment battle has paralyzed government in Brasilia, at a time when the country is preparing to host the Olympics in Rio de Janeiro in August and is also battling an epidemic of the Zika virus, which has been linked to birth defects in newborns.
Critics of the impeachment process say it has become a referendum on Rousseff's popularity - currently languishing in single digits - and sets a worrying precedent for ousting unpopular leaders in Congress in the future.
They note that Rousseff - who would be the first Brazilian president impeached for more than three decades - is accused of a budgetary sleight of hand commonly employed by many elected officials in Brazil.
Legislators denounced corruption and the economic downturn as they voted against Rousseff. One fired a popper of confetti into the air. But few of them mentioned the budgetary allegations.
However, business lobbies have thrown their weight behind the ouster of Rousseff, as they look to Temer to restore business confidence and growth to the $2 trillion economy.
Adriano Pires, head of the Rio de Janeiro-based Brazilian Infrastructure Institute, said Rousseff's departure could lead to an opening of the country's crucial oil sector. Union leaders, meanwhile, have voiced concerns about privatizations and job cuts.
Once regarded as an emerging markets powerhouse, Brazil has been hit by the end of a long commodities boom and lost its coveted investment grade credit rating in December.
So far this year, however, Brazil's stocks and currency have been among the world's best-performing assets on growing bets that Rousseff would be removed from office, allowing Temer to adopt more market-friendly policies.
While Rousseff herself has not been personally charged with corruption, many of the lawmakers who decided her fate on Sunday have been.
Congresso em Foco, a prominent watchdog group in Brasilia, said more than 300 of the legislators who voted - well over half the chamber - are under investigation for corruption, fraud or electoral crimes.
As they cast their vote, some lawmakers said the next politician to be impeached should be the man leading the proceedings, Speaker Eduardo Cunha. He is charged with corruption and money laundering in the kickback scandal involving Petrobras, and he also faces an ethics inquiry over undeclared Swiss bank accounts.
"God have pity on this nation," Cunha said as he cast his vote in favor of impeaching Rousseff.
(Additional reporting by Anthony Boadle, Stephen Eisenhammer and Lisandra Paraguassú in Brasilia, Guillermo Parra-Bernal in Sao Paulo and Jeb Blount in Rio de Janeiro; Writing by Daniel Flynn, Stephen Eisenhammer and Anthony Boadle; Editing by Kieran Murray and Frances Kerry)