Sunday 18 September 2016 17.34 EDT
First published on Sunday 18 September 2016 12.54 EDT

Berlin is likely to get the first leftwing triple-coalition government in its history, after Angela Merkel’s CDU party and the ruling Social Democrats both plummeted to their lowest result in the Germany capital.

Centre-left Social Democrats (SPD) came out top with 21.6% of the vote, ahead of the centre-right Christian Democratic Union (CDU) on 17.5%. Leftwing Die Linke came third on 15.7%, ahead of the Greens on 15.1%.

Anti-immigration populists Alternative für Deutschland are set to enter the German capital’s state parliament for the first time, with 14.1%.

Days before the election, mayor Michael Müller had warned that a double-digit score for the AfD “would be seen around the world as a sign of the return of the rightwing and the Nazis in Germany”.

The AfD’s Georg Pazderski and Joerg Meuthen celebrate the first exit polls of the Berlin city-state election. Photograph: Fabrizio Bensch/Reuters

“Berlin is not any old city”, the Social Democrat (SPD) politician wrote on Facebook on Thursday. “Berlin is the city that transformed itself from the capital of Hitler’s Nazi Germany into a beacon of freedom, tolerance, diversity and social cohesion.”

Before an election in which about 2.48m people were eligible to vote, Müller had indicated that he would prefer not to continue governing the city in a “grand coalition” between centre left and centre right, seeking a coalition with the Green party instead.

To gain a governing majority, the two parties will require the support of a third party, such as the Left party or the liberal Free Democrats, who managed to get back into parliament with 6.7%.

Berlin, once hailed as “poor but sexy” by its former mayor Klaus Wowereit, has seen unemployment rates drop below 10% and tax earnings rise in recent years. But a population growth of 40,000 residents a year has led to a build-up in state bureaucracy and given rise to fears of urban gentrification.

Asked by pollsters which issues had most influenced their votes, Berliners in the west and the east listed social justice, the local economy and the state of the education system above the management of the refugee crisis.

The month of campaigning in the German capital was dominated by rising rental prices and the ongoing fiasco of the new Berlin Brandenburg airport rather than refugees or fear of terror attacks.

Unlike most capitals in Europe, Berlin has higher public debts than other big cities such as Munich or Hamburg and continues to be subsidised by richer states around Germany.

Müller took over from Berlin’s long-term mayor Klaus Wowereit two years ago, after previously serving as party leader and senator. A more managerial figure than the often exuberant, openly gay Wowereit, Müller initially enjoyed high popularity ratings.

Yet, after 15 years of Social Democrat rule, Sunday’s result is a sobering step down from the 30.8% the party enjoyed at the height of the Wowereit era – and the 61.9% achieved under late mayor and ex-chancellor Willy Brandt. Like the CDU, the Social Democrats gained their lowest share of the vote in Berlin ever. In the history of modern Germany, no party has previously won an election with a similarly poor result.

The Pirate party, a band of internet freedom activists who managed to enter parliament in 2011, dropped below the 5% threshold.

But the result will hurt Merkel’s CDU most. After defeats for the Christian Democrats in Mecklenburg-Vorpommern, Rhineland-Westphalia and Baden–Württemberg, the Berlin result is the fourth blow in a row for the centre-right party, which came close to gaining an absolute majority at federal level only three years ago.

For the party leadership, it has become hard to ignore a pattern behind the results. In all four elections, established parties shed votes while the upstart AfD, founded in 2013, managed to achieve double digits.

As in the three previous votes, the CDU’s mayoral candidate in Berlin, Frank Henkel, got punished even though the party tried to distance themselves from their own chancellor’s stance over the refugee issue. Henkel, the deputy mayor, campaigned on a strict law and order ticket, at one point calling for a ban on the full facial veil for women and an end to dual citizenship – initiatives that were promptly watered down by the interior ministry.

Henkel’s profile as a law and order candidate was partly undermined by the fact that Berlin refugee authority LaGeSo gained a reputation for bureaucratic inefficiency and inhumane conditions under his own watch, leading to jibes of Berlin as a “failed city”.