Spain's main opposition Popular Party secured a landslide win in a regional election in Andalusia on Sunday, dealing a blow to Socialist Prime Minister Pedro Sanchez ahead of a national vote expected at the end of 2023.

The conservative Popular Party (PP) won 58 seats in the 109-seat Andalusian regional parliament, which will allow it to govern alone in Spain's most populous region, near final results showed.

That is more than double the 26 seats it won in the last election in 2018 when it ousted the Socialists from office from the southern region, a longtime stronghold for the party.

The Socialists captured 30 seats, its worst ever result in the region which is home to some 8.5 million people -- almost a fifth of Spain's population.

That is down from 33 in the last election in 2018 when they were ousted from power in the region by the PP in the wake of a scandal over the misuse of public funds.

The Socialists had governed Andalusia without interruption since 1982 when the region government was established.

"This victory is that of moderation and of another way of doing politics," said the PP's number two, Cuca Gamarra.

This is the Socialists' third consecutive regional election loss to the PP after votes in Madrid in May 2021 and Castilla y Leon in February.

Sanchez's leftist coalition government has been struggling to deal with the economic fallout from Russia's invasion of Ukraine, which has fuelled inflation worldwide, especially through increasing energy prices.

Losing in Andalusia would be a "severe blow" for the Socialists and would mean "Sanchez might face an uphill battle to get re-elected" next year, Antonio Barroso, an analyst at political consultancy Teneo, said before of the election.

"The PP seems to be gaining increasing momentum, and voter concerns about inflation might only make it more challenging for Sanchez to sell his government's achievements in the next legislative election," he added.

Over six million people are eligible to vote in Spain's most populous region of Andalusia
Over six million people are eligible to vote in Spain's most populous region of Andalusia AFP / CRISTINA QUICLER

Spain's inflation rate hit 8.7 percent in May, its highest level in decades.

Sanchez's government has rolled out a swathe of measures to help consumers, including a subsidy on fuel prices at the pump, an increase in the minimum wage, direct grants to truck drivers and financial support for some farmers.

The election outcome frees the PP from the need to govern in alliance with far-right party Vox, which won 14 seats.

Until now, Vox has supported the PP in Andalusia but from outside government.

But it had warned during the campaign that if the PP once again needed its support to govern, it would demand that it enters into government this time around.

The PP has governed Andalusia since 2018 in a coalition with smaller centre-right party Ciudadanos which did not win a single seat.

During the campaign the head of the PP in Andalusia, Juan Manuel Moreno Bonilla, had urged voters to deliver him a "strong" government that is not "weighed down" by Vox.

"This is a dream come true," he told reporters after the election results were announced.

Vox earlier this year entered a regional government for the first time since Spain returned to democracy in the 1970s in the Castilla and Leon region in a coalition with the PP.

Any deal with Vox in Andalusia would have complicated efforts by the PP's new national leader, Alberto Nunez Feijoo, to project a more moderate image.

The PP has sought to present itself in Andalusia as a centrist "sensible alternative, an effort to present itself as an option from the centre," University of Granada political science professor Oscar Garcia Luengo told AFP.

The strategy won the PP one million new voters, including 300,000 who voted for Sanchez in the last national election in 2019, Narciso Michavila, head of GAD3 pollsters, told daily ABC.