Spain’s conservative People’s party scored a spectacular victory in a pivotal regional election in Madrid on Tuesday — doubling its vote, inflicting a humiliating defeat on the country’s governing Socialists and prompting the resignation of the leader of the radical leftwing Podemos party.

The result is a personal triumph for Isabel Díaz Ayuso, the PP head of the Madrid region who called the election, although she will have to rely on the support of the hard-right Vox party.

It is a huge boost for the PP, Spain’s main opposition party, after a string of recent setbacks including the worst results in its history in general elections in 2019 and gaining only 4 per cent of the vote in regional polls in Catalonia in February.

By contrast, the night was a disaster for prime minister Pedro Sánchez and his Socialists, whose vote slid 10 percentage points, slipping behind an upstart leftwing group called More Madrid.

Díaz Ayuso, who campaigned on the slogan “Freedom”, has clashed repeatedly with the Socialist-led national government over coronavirus policy, imposing fewer restrictions than the rest of the country and keeping the region’s hospitality industry open for months.

In her victory speech on Tuesday night she said that the days of Sánchez’s hold on power “are numbered”.

“Today freedom has won in Madrid; tomorrow, it will win in all of Spain,” added Pablo Casado, the PP’s national leader.

The election also signified the end of the political career of Pablo Iglesias, the leader of the radical left Podemos grouping, who had resigned as deputy prime minister in the national coalition to run in the Madrid race — but came only fifth.

On Tuesday night, Iglesias, who labelled the results a “tragedy”, said he was quitting all his remaining posts and leaving politics.

With 99 per cent of the vote counted in the greater Madrid region, which has a population of 6.6m people, the PP had secured 44.7 per cent — 22 percentage points more than in the previous election in 2019 — compared with about 17 per cent apiece for More Madrid and the Socialists. With 65 deputies, the PP is just short of a majority in the 136-member regional assembly.

The PP has been trying to reverse the fragmentation of the Spanish right in recent years, and owed most of its increase in support to the collapse of the centrist Ciudadanos party. Its former coalition partner failed to clear the 5 per cent threshold for representation.

But the PP remains dependent on Vox, which immediately pledged its support for Díaz Ayuso.

Many analysts argue that the race will have far-ranging consequences, given the importance of the Spanish regions in the country’s decentralised system of government, the role of Madrid as the nation’s economic powerhouse and Sánchez’s close involvement in the campaign.

As the results came in on Tuesday night, crowds sang and danced outside PP headquarters, celebrating what they hailed as a devastating defeat for Sánchez and his minority government.

The vote comes at a highly sensitive time, with the national emergency rules underpinning Spain’s coronavirus restrictions lapsing on Sunday, the Sánchez government proceeding with plans to spend €140bn in EU recovery funds, and the possibility that other regional elections — for example in Andalucía — could be triggered by the success of the PP’s gambit.

“Sánchez is in a very bad position,” said Nacho Torreblanca of the European Council on Foreign Relations. “The Socialists have not been able to win over votes either from Ciudadanos or from the left . . . Now the question is whether Sánchez can govern with the deadweight of Podemos, trusting everything to the EU funds.”

The Socialists had come first in the previous Madrid poll, in 2019, but proved unable to form a coalition. On Tuesday night, José Luis Ábalos, a senior Socialist leader, said the results were “disappointing but do not reflect all of Spain.”

Turnout was high, with almost 70 per cent participation as of 7pm, and long queues at polling booths throughout the region.