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 won 52 per cent of the nationwide vote, with around 90 per cent of the votes counted - significantly down from the 65 per cent 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."