Angela Merkel's ruling CDU party has been beaten into third place by an anti-immigrant and anti-Islam party in elections in a north-eastern German state.
The Alternative fuer Deutschland (AfD) party took just under 21% of the vote behind the centre-left SPD's 30%.
The German chancellor's CDU was backed by only 19% of voters, its worst ever result in the state.
The vote was seen as a key test before German parliamentary elections in 2017.
Before the vote in Mecklenburg-West Pomerania, in the former East Germany, all of Germany's other parties ruled out forming a governing coalition with the AfD. But the party, formed only three years ago, is already represented in nine of Germany's 16 state parliaments.
'Rapefugee' message in Rostock as AfD challenges Merkel
Germany jolted by AfD success
Is Merkel really on the ropes?
One leading CDU politician called the result catastrophic, while another, Wolfgang Bosbach, said the arrival of hundreds of thousands of migrants without documents had "put the wind in the AfD's sails".
Analysis: By Jenny Hill, BBC Berlin correspondent
This is humiliating for Angela Merkel - not least because this was on home turf. Mrs Merkel's constituency is in Mecklenburg-West Pomerania.
This election - which was seen as a significant test ahead of next year's general election - was all about her refugee policy. For a year she's insisted 'Wir schaffen es' (we can do it) but German voters aren't convinced.
Alternative fuer Deutschland's anti immigrant and increasingly strident anti-Islam message has a powerful appeal to people concerned about integration and worried about domestic security.
It doesn't look good for Mrs Merkel. Her approval ratings are at a five-year low. But don't be tempted to write her off just yet - she has a habit of bouncing back and there is no serious contender waiting in the wings to replace her.
Under her leadership, Germany has been taking in large numbers of refugees and migrants - 1.1 million last year - and anti-immigrant feeling has increased.
The AfD, initially an anti-euro party, has enjoyed a rapid rise as the party of choice for voters dismayed by Mrs Merkel's policy.
But its political power is limited and critics accuse it of engaging in xenophobic scaremongering.
The CDU has been the junior coalition partner in Mecklenburg-West Pomerania since 2006 and is likely to remain in the governing coalition. However, its 19% in the election is its worst ever result in the state, German broadcasters said.
"The strong performance of AfD is bitter for many, for everyone in our party," said CDU secretary general Peter Tauber. "A sizeable number of people wanted to voice their displeasure and to protest. And we saw that particularly in discussions about refugees."
BBC Berlin correspondent Damien McGuinness says that following her political embarrassment, Mrs Merkel will now come under greater pressure to change her welcoming position on refugees.
Addressing supporters, local AfD leader Leif-Erik Holm said: "Perhaps this is the beginning of the end of Angela Merkel's chancellorship today."
Mrs Merkel, who is in China for the G20 summit, told Bild newspaper on Saturday: "We did not reduce benefits for anyone in Germany as a result of the aid for refugees. In fact, we actually saw social improvements in some areas.
"We took nothing away from people here. We are still achieving our big goal of maintaining and improving the quality of life in Germany."