Spain faced a dramatically changed political landscape on Monday after voters in local elections abandoned traditional parties, with anti-austerity groups topping polls in Barcelona and possibly taking power in Madrid.

The political shakeup following Sunday’s elections was driven by voter anger over a sky-high unemployment rate of 24 percent, government spending cuts and corruption scandals.

The crisis has rocked both Prime Minister Mariano Rajoy’s Popular Party (PP) and the main opposition Socialists, which have alternated in government for nearly four decades.

In a test of the national mood ahead of general elections expected in November, the PP managed the most votes but still lost its absolute majorities in most regions and even fared poorly in historical strongholds.

Combined, the PP and the Socialists captured just 52 percent of the vote nationwide, down from 65 percent four years ago.

“We have lost a large part of the support the Spanish people gave us in 2011,” when the country held its last election, Rajoy told a news conference on Monday.

“We have to be closer to the Spanish people and communicate better with them.”

But he insisted he could still win the general election and reiterated that the economic recovery was his top priority.

Support instead switched to new centre-right party Ciudadanos and anti-austerity party Podemos, which was born out of the “Indignado” (“Outraged”) protests against corruption and high unemployment that swamped the streets during the recent economic crisis.

A Podemos-backed candidate for mayor won in Barcelona and another looked poised to take power in Madrid, a longtime conservative stronghold.

The Madrid candidate Manuel Carmena told reporters on Monday she expected to become mayor, implying she would make an alliance with the Socialists to form a majority to beat the PP.

She said she had already got to work on the reforms she planned as mayor, starting with moves to stop evictions of ruined homeowners.

“We want to get to work straightaway,” she said.

– ‘Fascinating evolution’ –

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

“We are seeing a fascinating evolution that could lead to an update of the political system, which is more plural just as Spanish society is more diverse,” said Narciso Michavila, who heads the GAD3 polling firm.

Spain has little tradition of compromise politics and the results of the polls will likely lead to weeks of negotiations.

The difficulty that parties will have in reaching pacts can already be seen in Spain’s most populous region, Andalusia, which held its parliamentary election in March.

Two months after the election the Socialist candidate who won the most votes remains unable to persuade the other parties to vote to install her as regional president.

– Podemos reaches out –

Pedro Sanchez, the leader of the Socialists which captured 25 percent of the vote nationwide, said the results showed voters wanted a swing to the left.

He said his party would work to ensure that “progressive governments” emerged from Sunday’s elections.

The leader of Podemos, pony-tailed political science professor Pablo Iglesias, told public television TVE that his party was “reaching out to whoever wants to reach an agreement with us”.

Analysts said it was in the interest of both Podemos and Ciudadanos to reach agreements with the established parties in the regions where they are kingmakers.

“If in the end they do not arrive at pacts and create stability, in four years these new parties will disappear,” Michavila said.

Jose Fernandez-Albertos, a political scientist at state research institute CSIC, said he did not rule out “that certain regions will have to call fresh elections, due a failure to reach an agreement on forming a government”.