Voters have punished Spain's mainstream political parties in local elections as many people switched their allegiance to new groups campaigning on a promise of change amid chafing austerity policies, high unemployment and corruption scandals.

The ruling conservative Popular Party and the main opposition Socialist Party, which have alternated in government for nearly 40 years, surrendered control of some city halls and regional governments.

They snared 52% of the nationwide vote, with around 90% of the votes counted - significantly down from the 65% of the vote the parties gathered in elections four years ago, but short of the political meltdown that some feared.

Meanwhile, the radical left-wing We Can group and business-friendly Citizens party - grassroot organisations which began operating on a national level just a year ago, were the third and fourth most popular parties, in a landmark result that could leave them holding the balance of power in local governments.

"We would have liked the decline of the old parties to have been quicker," said Pablo Iglesias, the leader of We Can. "But circumstances compel us to keep working on it."

Spain is not the first southern European country to witness a shift in the political centre of gravity since Europe's debt crisis prompted governments to slash spending on such cherished budget items as public health and education.

In recent years, the traditional parties of governments in Italy and Greece have also seen their influence eroded by new and often radical choices.

In Spain, corruption scandals dogging the two mainstream parties have fuelled voter disaffection with business-as-usual choices.

The elections, for seats in more than 8,100 Spanish town halls and 13 of 17 regional parliaments, were seen as a barometer for scheduled national elections in the European Union's fifth-largest economy at the end of the year.

The Popular Party lost control of prestigious Madrid city hall, which it has run for more than 20 years. A coalition of new parties, including We Can, came out on top there.

But the PP avoided the disastrous result that some analysts said was possible with a 23% jobless rate - and more than double that for people under 25 - turning many against the government.

In local elections four years ago, the PP had absolute majorities in eight regional governments, allowing it to run them without making political alliances. This time it won none outright, meaning the PP will have to seek pacts with other parties, perhaps leaving the newcomers as power brokers.

"The elections confirm the fragmentation of the Spanish party system, with new parties having a lot of appeal, but the main parties will survive and stay as the main players," said Antonio Barroso, an analyst with the London-based Teneo Intelligence political-risk consultancy.

He believes Spain's rapidly improving economy, among the fastest-growing in the EU, will help prime minister Mariano Rajoy, the PP leader, get re-elected.

Things were bleak for the Socialists. The We Can group, which is targeting the same left-leaning voters, is right on its heels.

There was also a memorable upset in Barcelona where Ada Colau, a popular anti-eviction campaigner backed by We Can, capitalised on local disaffection and unseated the region's long dominant and conservative Convergence and Union party.

"Common people who have not had power - whether it be economic, political, media or legal - had a historic opportunity and knew how to take advantage of it," she told supporters. "The desperation had taken hold and we have shown there indeed is an alternative."

In Madrid, where protesters angry with austerity measures and corruption camped out in the Puerta del Sol square for weeks in 2011 and helped fuel the worldwide Occupy movement, the Popular Party lost its long-standing majority.

"Voting for We Can was the only option for me," said student Mikel Redondo, 19, in Madrid. "The political establishment needs to be shaken up and it's the best option to achieve that."

PA Media