The socialist system built by Hugo Chavez faced its gravest electoral test Sunday as Venezuelans cast ballots in what seems to have become a tightening race for control of the national legislature.

Voters woke to state-sponsored fireworks and music in working-class parts of Caracas. Wealthier neighborhoods, which tend to favor the opposition, were spared the early morning cacophony.

Venezuelans of all inclinations began lining up before polling stations opened, anxious to cast their ballots early in case violence should break out later in the day.

"I'm voting for the opposition, and then I'm going home to read newspapers all day," said Nora Beatriz, 78. "You can't believe the level of hate there is here now. You say you don't like the socialists and you get screamed at, yelled at, and who knows what else."

Until recently, the opposition was seen as coasting to its first major electoral victory since Chavez became president in 1998, with Venezuelans tired of rampant crime, routine shortages of basic goods and inflation pushing well into triple digits. The economic crisis has worsened with this year's slump in oil revenue, which funds almost all public spending.

But support for President Nicolas Maduro's rule, a good proxy in deeply polarized Venezuela, recently jumped 11 points, to 32 percent in late November, according to a survey by respected local pollster Datanalisis. Analysts attributed the bounce to an aggressive government campaign of funneling resource to key districts and warning voters that Chavez's legacy of social programs would be lost if the opposition took control of the National Assembly.

Douglas Flores was eager to vote for the ruling party Sunday out of gratitude for the new house the government gave his family three years ago, allowing them to move out of the plywood shack where he grew up.

"I don't believe it when the opposition says they'll look out for the poor. Those guys were in power for years before Chavez came, and they never gave us a single thing," he said as he hawked empanadas to voters waiting in line.

A small opposition majority in the new 167-seat National Assembly could create only minor inconveniences for Maduro, such as denying him a budget for foreign travel and having committees scrutinize the executive's record. Some hardliners are also 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, would require new laws needing at least a three-fifths majority, or 101 seats — two more than now held by the socialists. Maduro's near-complete grip on other branches of government like the Supreme Court mean he can easily outflank a hostile congress.

It's also possible the Democratic Unity opposition coalition could win the nationwide popular vote by a large margin but fail to win even a majority in the legislature because of the underrepresentation of Venezuela's urban areas, where frustration with the government runs highest.

The opposition, with little cash and little access to broadcast media, has struggled to compete in far-flung rural districts against the government's campaign machine. In 2010, voting nationwide was almost evenly split yet the government ended up seating 33 more lawmakers due to Venezuela's complicated electoral system.

Still, even a small victory would provide an important lift to the frequently outmaneuvered opposition. The socialist party has often touted its unbroken chain of electoral victories over the past 17 years to defend itself against allegations that it's undemocratic.

More than 163,000 police and troops have been deployed around the country ahead of Sunday's vote, but many Venezuelans still fear postelection violence. Maduro reiterated his promise this week to take to the streets if his party lost. Opposition leaders said that if their coalition failed to win, it would mean the state cheated.

During the campaign, the government drew criticism from the U.S. and other governments for tactics that appeared to tilt the playing field, including barring high-profile opposition leaders from running and printing a confusing ballot with a mysterious party listed next to the opposition coalition with a nearly identical logo and name.

The U.S. State Department on Friday muted some of its past criticism but said it would be watching closely, and called on the National Electoral Council to ensure a fair vote.