By Andrew Cawthorne and Leon Wietfeld

CARACAS (Reuters) - President Nicolas Maduro has set his sights on Venezuela's 2018 presidential election after the ruling Socialist Party dominated mayoral polls with the help of a partial boycott by a divided opposition.

Enjoying a political breather after a year of ferocious domestic protests and damaging foreign sanctions, the 55-year-old successor to Hugo Chavez said the government had won at least 90 percent of the 335 mayorships in Sunday's election.

Latest official results gave him 21 of 23 state capitals as well as Caracas' main district, with full results due later on Monday. The landslide win for the socialists was no surprise, given three of the biggest opposition parties did not field candidates.

The elections left Maduro favorite to be the socialist candidate in next year's presidential race, despite the ambitions of rivals within government and an economic crisis that has pummeled the OPEC nation since his 2013 election.

"Let's get ready for 2018!" he told cheering supporters in a Caracas square shortly before midnight on Sunday, next to a statue of Venezuela's independence hero Simon Bolivar.

Maduro also declared fixing Venezuela's broken economy a priority. But opponents and even some government dissenters say it is his stubborn adherence to Chavez-era economic policies, such as currency controls, that is to blame for the crisis.

Venezuela's 30 million people are enduring one of the worst economic meltdowns in recent Latin American history. Millions are skipping meals, missing medicines, and lining up for hours at shops during acute shortages and crippling inflation.

Opposition parties said Sunday's vote was full of irregularities and meaningless, and reiterated demands for changes to the electoral system for the 2018 vote.

"What we saw yesterday was an electoral farce that in no way represents the will of the people," said Popular Will party leader Juan Andres Mejia, citing abuse of state resources and coercion of government employees to vote.

Story continues

MADURO 'WELL-POSITIONED' FOR RE-ELECTION

Three of the opposition coalition's main parties - Popular Will, Justice First and Democratic Action - boycotted Sunday's polls, saying the election board was a pawn of the government.

But other opposition parties did put up candidates, adding to confusion and acrimony within opposition ranks.

Maduro said the three abstaining parties should be banned from participating in future elections. That brought a rebuke from the U.S. State Department, which called his remarks "another extreme measure to close democratic space in Venezuela and consolidate power in his authoritarian dictatorship."

Venezuela's presidential election has traditionally been held in December, but there is speculation in political circles that it will be brought forward to the first half of 2018 so the socialists can take advantage of the opposition's disarray.

"Despite the regime's economic incompetence and the inherent weaknesses of Maduro's authoritarianism, he is well positioned to achieve re-election next year," said Nicholas Watson, of the Teneo Intelligence consultancy.

With its most popular leaders barred - Leopoldo Lopez is under arrest and Henrique Capriles is prohibited from office - the opposition may struggle to find a flagbearer.

Uniting parties and reigniting enthusiasm among despondent grassroots supporters will also be huge challenges.

Street protests earlier in 2017 put pressure on Maduro and left 125 people dead. Foreign pressure hardened too, with U.S. President Donald Trump imposing sanctions on Venezuela for alleged government rights abuses and corruption.

Yet after facing down demonstrators, pushing through a controversial legislative superbody in a July vote also boycotted by the opposition, and notching a majority in October gubernatorial polls, Maduro has ridden out the storm for now.

"I think the current government can fix things if they are allowed to get on with it," said mechanic Melix Jordan, 56, voting for the government in a rural part of Paraguana.

Social discontent is running deep, however. There is no sign so far of an alternative presidential candidate, despite calls in some quarters for popular billionaire businessman Lorenzo Mendoza to run.

"My vote maybe doesn't change anything," said gardener Hector Machado, 64, who voted for the opposition in Tachira state. "But I still have hope for something better next year."

(Additional reporting by Mircely Guanipa in Paraguana and Anggy Polanco in San Cristobal and Alexandra Ulmer, Eyanir Chinea and Corina Pons in Caracas, Editing by Jeffrey Benkoe and Rosalba O'Brien)