BRASILIA, April 18 (Reuters) - Brazil's leftist President Dilma Rousseff suffered a humiliating loss in a crucial impeachment vote in the lower house of Congress on Sunday and is 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 favour of impeachment, versus 137 against, and seven abstentions. Two lawmakers did not show up to vote.
Brazilian financial markets were expected to open higher on Monday after the vote - a major step toward ending 13 years of the left-leaning Workers' Party rule in the world's ninth largest economy.
If the Senate now votes by a simple majority in early May to proceed with the impeachment, as expected, Rousseff would be suspended from her post and be 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 destabilise 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 the vast nation, 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-metre) security barrier ran for more than 1 km to separate rival demonstrations, a symbol of the political rift that has emerged in one of the world's most unequal societies.
As the vote came to an end, hundreds of Rousseff supporters sat downcast on red flags and banners on the grass. A young couple, on the verge of tears, hugged each other.
On the pro-impeachment side of the wall, protesters sang and danced, drinking beer and munching popcorn. Some took selfies and performed handstands, celebrating a decision that many said was a victory against corruption.
"Impeachment sends a clear message that the politics of this country needs to be cleaned up," said Alesandra Dantas, a 28-year-old social worker.
The impeachment battle has paralysed the activity of government in Brasilia, before the Olympics are held in Rio de Janeiro in August and as it seeks to battle 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 - which sets a worrying precedent for ousting unpopular leaders 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.
With Brazilians transfixed by the congressional vote, broadcast live on television, 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 the departure of Rousseff could lead to an opening of the country's crucial oil sector. Union leaders, meanwhile, have voiced fears about privatisations 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.
In a sign that rally could continue, an exchange-traded fund of Brazilian equities gained 3.8 percent shortly after the result was announced.
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 Peter Cooney, Kieran Murray and Mary Milliken