CARACAS, VENEZUELA - Venezuela's ruling socialist party swept mayoral races in most of the state capitals and major cities in Sunday elections boycotted by several opposition parties, officials announced.

The ruling party won in 41 of 42 cities where a winner was declared, according to early official results. The opposition even lost in strongholds such as Maracaibo and the Caracas-area district of Sucre.

Around 47 percent of eligible voters cast ballots. That was down from 58 percent in municipal elections four years ago, as three of the four major opposition parties refused to field candidates because of irregularities and allegations of fraud in recent gubernatorial elections.

The election of mayors in all of Venezuela's 335 municipalities was the last national balloting before next year's presidential contest, in which socialist President Nicolas Maduro is expected to seek re-election despite his steep unpopularity.

Various polling places appeared to be sparsely filled throughout Sunday, with only handfuls of people seen casting ballots.

"Let's hope they're late sleepers and this isn't a phenomenon of abstention,'' said retired librarian Jose Tomas Franco, an early morning voter in the capital of Caracas who called the low turnout "alarming.''

The elections took place against a backdrop of soaring inflation, shortages of food and medicine, and charges that Maduro's government has undermined Venezuela's democracy by imprisoning dissidents and usurping the powers of the opposition-controlled National Assembly.

Economic and political crises have caused the president's approval rating to plunge, although the opposition has been largely unable to capitalize on Maduro's unpopularity.

Venezuela's President Nicolas Maduro and his wife, Venezuela's President Nicolas Maduro and his wife, Cilia Flores, inspect the rebuilding of the Humboldt Hotel, a state-run hotel, at the Avila mountain in Caracas, Venezuela, Dec. 7, 2017. Venezuela's President Nicolas Maduro and his wife, Cilia Flores, inspect the rebuilding of the Humboldt Hotel, a state-run hotel, at the Avila mountain in Caracas, Venezuela, Dec. 7, 2017.

Opposition candidates suffered a crushing defeat in October's gubernatorial elections, winning just five of 23 races amid allegations of official vote-buying and other irregularities.

Three of the four biggest opposition parties said they boycotted Sunday's mayoral races in protest of what they called a rigged electoral system.

Maduro responded on state television after casting his vote by threatening to ban political groups that boycotted the mayoral races from future political contests.

"A party that has not participated today cannot participate anymore,'' said Maduro, who called Sunday's turnout "extraordinary.''

Given the opposition's disarray, political analysts said they doubted Maduro's opponents would be able to rally behind a single candidate in next year's presidential election.

"The opposition is condemned to trying to find a solution to its internal problems,'' said Edgard Gutierrez, coordinator of local pollster Venebarometro. "Either that or simply not compete in 2018.''

The last time the opposition refused to compete, in congressional elections in 2005, it strengthened the government's hand for years.

This has been a turbulent year for Venezuela, which holds the world's largest oil reserves but has been battered by a fall in crude prices and low production. The country saw months of protests that left more than 120 dead earlier this year, and it is now facing U.S. economic sanctions as it seeks to refinance a huge international debt.

Raul Contreras, a salesman, said he thought little would change regardless of Sunday's outcome.

"As Venezuelans, we're very disappointed with our politicians,'' he said. "Things can only change here after the presidential elections.''