Thousands of supporters of Spain's anti-austerity parties took to the streets of Madrid last night as Spain's ruling People's Party took a battering in regional and local elections.

Voters punished Prime Minister Mariano Rajoy for four years of severe spending cuts and a string of corruption scandals.

In a test of the national mood ahead of general elections expected in November, the PP suffered its worst result in more than 20 years to herald an uncertain era of coalition as new parties rose to fragment the vote.

Spaniards rejected the stability offered by the PP and rival Socialists, which have alternated in power since the end of dictatorship 40 years ago, and opted for change in the shape of new parties - market-friendly Ciudadanos ('Citizens') and anti-austerity Podemos ('We Can').

In Madrid, where there has been a PP mayor since 1991, Prime Minister Rajoy's party marginally beat a leftist platform backed by Podemos and headed by 71-year-old retired judge Manuela Carmena.

However, there as well the Podemos-backed alliance is likely to team up with the Socialists to win power.

The Podemos leader, Pablo Iglesias, joined the celebration and introduced Ms Carmena as the new mayor of Madrid.

Prime Minister Rajoy's future looked bleak as his strategy to bet on an accelerating economic rebound to win a second term later this year was seriously undermined by his party's poor showing.

Although the PP got more votes than any other party, along with the rival Socialists, it fell short of overall majorities in most areas.

The two parties will have to negotiate coalitions with minority parties in the 13 of Spain's 17 regions that voted on Sunday alongside more than 8,000 towns and cities.

The PP got its worst result in countrywide municipal elections since 1991 and lost its absolute majority in regional bastions Madrid and Valencia, where potential left-wing coalitions could send the party into opposition for the first time in 20 years.

Podemos, often compared to Greek radical left party Syriza, had toned down its policies in recent weeks, scrapping more extreme ideas like defaulting on the national debt.