(BBC.COM) German Chancellor Angela Merkel has been re-elected for a fourth term while nationalists have made a historic breakthrough in federal elections, exit polls suggest.
Her conservative CDU/CSU alliance is set to remain the largest party in the parliament, with 32.5% of the vote.
Its outgoing coalition partner, the social democratic SPD, says it will go into opposition after winning 20%.
The nationalist AfD is on track to become the third party, with 13.5%.
The performance, better than forecast in opinion polls, means the right-wing party will have seats in the Bundestag for the first time.
Dozens of protesters have gathered outside the party’s headquarters in Berlin, some with placards saying “Refugees are welcome”.
What does the result mean for Mrs Merkel?
While her alliance has remained the largest party, the numbers, if confirmed, are the worst result for the alliance between the Christian Democrat (CDU) and the Christian Social Union (CSU) under Mrs Merkel’s leadership.
Addressing supporters, Mrs Merkel, who has been in the job for 12 years, said she had hoped for a “better result”.
She added that she would listen to the “concerns, worries and anxieties” of voters of the anti-immigration, anti-Islam Alternative for Germany (AfD) in order to win them back.
Mrs Merkel also said her government would have to deal with economic and security issues as well as addressing the root causes of migration – one of the main reasons behind AfD’s result.
“Today we can say that we now have a mandate to assume responsibility and we’re going to assume this responsibility calmly, talking with our partners of course.”
Why this vote matters
The result is disastrous for Mrs Merkel, BBC Berlin correspondent Jenny Hill says.
The chancellor is being punished for opening Germany’s door to almost 900,000 undocumented refugees and migrants, many of them from war-torn, mainly Muslim countries like Syria, our correspondent adds.
What are her coalition options?
The exit polls suggest the Social Democrats (SPD), led by Martin Schulz, have fallen to a new post-World War Two low. He said the result meant the end of the “grand coalition” with Mrs Merkel’s alliance.
“It’s a difficult and bitter day for social democrats in Germany,” Mr Schulz told supporters. “We haven’t reached our objective.”
With the possibility of an alliance with the SPD rejected, Mrs Merkel’s options are narrow, and the process of forming a new coalition could take months.
The projections suggest that six parties will be in the German parliament for the first time since World War Two.
Election marks unprecedented shift
What does Alternative for Germany (AfD) want?
The most likely scenario is of a “Jamaica” coalition, so-called because of the colours of Jamaica’s flag. It includes the black CDU/CSU, the yellow, business-friendly Free Democrats (FDP) – who are returning to parliament after a four-year hiatus – and the Greens.
It is not a marriage made in heaven, as the Greens want to phase out 20 coal-fired power plants and the FDP disagree, but it is the only formation that would guarantee enough seats in the new Bundestag, German broadcaster ZDF says.
All parties have rejected working with the AfD.
What about the AfD?
The party has capitalised on a backlash against Mrs Merkel’s policy towards migrants and refugees. Its programme called for a ban on minarets and considered Islam incompatible with German culture.
Prominent AfD figure Frauke Petry said on Twitter (in German) that Germany had experienced an incomparable “political earthquake”.
Meanwhile, Beatrix van Storch, one of the party’s leaders, told the BBC that the result would change the political system in Germany, giving “a voice” to the people she said were not represented in the last parliament.
“We’ll start debates on migration, we’ll start debates on Islam, we’ll start debates on ever closer union.”