Venezuela's opposition has won control of the National Assembly by a landslide, trouncing the ruling party and altering the balance of power after almost 17 years of socialist rule.

The opposition coalition won at least 99 seats in the incoming 167-seat legislature, electoral authorities announced after midnight Sunday. The ruling socialist party won 46 seats. The 19 remaining races remain up for grabs but if enough are won by the opposition it could give the coalition a two-thirds supermajority needed to strongly challenge President Nicolas Maduro's grip on power.

The streets of the Venezuelan capital of Caracas broke out in shouts of joy, fireworks and car honks after National Electoral Council President Tibisay Lucena announced the partial results six hours after polls closed. In the plaza in wealthy eastern Caracas that was the epicenter of last year's bloody anti-government protests, a small group of opponents, some of them sipping champagne, burned red shirts that are the obligatory revolutionary attire.

In pictures: Venezuela elections Show all 10 1 /10 In pictures: Venezuela elections In pictures: Venezuela elections An opposition masked man holds a Venezuelan national flag as supporters of Venezuelan opposition coalition Mesa de Unidad Democratica (MUD) celebrate the victory of the party in Caracas, after the Venezuelan National Election Council's President, Tibisay Lucena (unseen), announced that MUD won the legislative election EPA In pictures: Venezuela elections Several people celebrate in a street in Caracas EPA In pictures: Venezuela elections A woman reacts as people celebrates in a street in Caracas EPA In pictures: Venezuela elections Humberto Lopez, known as "El Che", reacts as National Electoral Council (CNE) President Tibisay Lucena announces the official results of parliamentary elections in Caracas. Venezuela's opposition won control of the legislature from the ruling Socialists for the first time in 16 years, giving them a long-sought platform to challenge President Nicolas Maduro Reuters In pictures: Venezuela elections Venezuelan President Nicolas Maduro speaks after listening to the results of the legislative elections in Caracas. The Venezuelan opposition won national elections by a landslide, with at least 99 of the 167 seats confirmed for the alliance of the Democratic Unity Roundtable (MUD). It was the first defeat of the socialist movement since its founder Hugo Chavez came to power in a 1998 electionelection In pictures: Venezuela elections Opposition leaders, from left to right, Lilian Tintori, wife of jailed Venezuelan opposition leader Leopoldo Lopez, Freddy Guevara, of the Voluntad Popular party, Jesus Torrealba, head of the Democratic Unity Movement (MUD) party and deputy Julio Borges celebrate in Caracas. Venezuela's opposition won control of the National Assembly by a landslide, delivering a major setback to the ruling party and altering the balance of power after 17 years of socialist rule AP In pictures: Venezuela elections Venezuelan opposition leader Henrique Capriles votes in the legislative election, in Caracas Getty Images In pictures: Venezuela elections A citizen votes in the legislative election in Caracas Getty Images In pictures: Venezuela elections Presidential Guard officers hold their national identification cards as they enter a polling station during congressional elections in Caracas AP In pictures: Venezuela elections Voters enter a public school serving as a polling station, decorated with an image of Venezuela's late President Hugo Chavez, right, and current President Nicolas Maduro, during congressional elections in Caracas. The system built by Chavez faces its gravest electoral test as voters cast ballots in what seems to have become a tightening race for control of the national legislature AP

Within seconds, Maduro recognized the opposition's win, saying that despite an adverse result Venezuela's democracy had triumphed. But he recalled the long history of US-supported coups in Latin America in blaming the "circumstantial" loss on a conservative "counter revolution" trying to sabotage the oil-dependent economy and destabilize his rule,

"I can say today that the economic war has triumphed," Maduro, surrounded by his party's top leadership, said from the presidential palace.

Opposition leaders meanwhile spoke in strident terms, a prelude to what's likely to be a period of intense political fighting in a deeply polarized country mired in an economic crisis. Voter turnout was a stunning 74 percent, near levels normally seen in presidential voting, as Venezuelans punished Maduro's government for widespread shortages, a plunging currency and triple-digit inflation that has brought the economy to the edge of collapse.

"Venezuelan families are tired of living the consequences of the failure," Jesus Torrealba, head of the Democratic Unity opposition coalition, told supporters at campaign headquarters. "The country wants change and that change is beginning today."

The opposition victory deals a serious setback to the socialist revolution started almost 17 years ago by the late Hugo Chavez, who until his death in 2013 had an almost-magical hold on the political aspirations of Venezuela's long-excluded masses.

It was also a major blow to Latin America's left, which gained power in the wake of Chavez's ascent but more recently has been struggling in the face of a region-wide economic slowdown and voter fatigue in some countries with rampant corruption. Last month, Argentines elected a conservative businessman over the chosen successor of Cristina Fernandez, who was a close ally of Chavez. In Brazil, President Dilma Rousseff is battling impeachment over a corruption scandal in her long-ruling Workers' Party.

Maduro had repeatedly vowed in recent weeks to take to the streets and defend his mentor Chavez's legacy if his party lost. But on Sunday night he softened his tone, urging his supporters to regroup from the loss in calm.

"I call on all of our people to recognize in peace these results and re-evaluate many political aspects of the revolution," he said.

But some government supporters were bracing for a fight.

"Now everything will just get worse. The Chavistas will go to war with the opposition," said Diana Areaz, who waited with her friend who makes a living dressing up as Cuban revolutionary Ernesto "Che" Guevara to hear the results.

For Areaz, who was 8 years old when Chavez came to power, the defeat was unimaginable.

"I've only ever known one government. But the truth is Maduro abandoned the revolution, and now it's hardly a revolution at all," she

The result marked the opposition's first major electoral victory since Chavez became president.

Voting was mostly peaceful, though fears of unrest prompted some Venezuelans to line up before dawn so they could cast their ballots and go home to wait for results. Foreshadowing the historic win, several ruling party governors were caught on film braving boos and insults as they entered their polling places, including Chavez's brother Adan.

The opposition is likely to use its newfound leverage to pass an amnesty for dozens of opponents jailed during last year's protests. Some hardliners are vowing to seek a recall referendum to cut short Maduro's term before it ends in 2019.

But reining in Maduro, who became president after Chavez died in 2013, will be tough. Maduro's near-complete grip on other branches of government like the Supreme Court mean he can easily outflank a hostile congress. And some have already floated the idea that outgoing lawmakers can pass a law granting Maduro special decree powers to ride roughshod over the new congress, which won't be sworn in until January.

Their work will be easier if they obtain a two-thirds majority of 112 lawmakers - still a possibility if enough of the undecided races break the opposition's way. Such a super majority would allow the congress to sack supreme court justices, pass major legislation and even convene a convention to rewrite Chavez's 1999 constitution.

Additional reporting by Fabiola Sanchez and Jorge Reuda