The party of German Chancellor Angela Merkel has suffered defeats in two of three states holding regional elections, exit polls suggest.
They indicate the Christian Democrats lost support in Baden-Wuerttemberg and Rhineland Palatinate, but remain the largest party in Saxony-Anhalt.
The anti-migrant AfD achieved gains in all three states, exit polls indicate.
The elections were seen as a test of support for Chancellor Merkel’s policy of accommodating refugees.
More than a million migrants and refugees entered Germany in 2015.
In the western state of Baden-Wuerttemberg, a former stronghold of the conservative Christian Democrats (CDU), support for the party reached a historic low of about 27%, the exit polls suggest.
They say the Green-led coalition currently in power won the election.
Already represented in five of Germany’s 16 regional parliaments, the AfD has campaigned on slogans such as “Secure the borders” and “Stop the asylum chaos”.
German Vice-Chancellor Sigmar Gabriel said on Saturday that gains for the AfD would not change his government’s stance on immigration.
He said: “There is a clear position that we stand by: humanity and solidarity. We will not change our position now.
But in Berlin on Saturday, about 2,000 right-wing demonstrators carrying German flags chanted “Merkel must go!” and “We are the people!”.
The poor results could put additional pressure on Mrs Merkel, just as she is trying to push through an EU deal with Turkey to reduce the numbers of migrants and refugees entering western Europe.
As Europe’s largest economy, Germany has a leading role in policy-making for the European Union.
At a summit earlier this week, the chancellor promoted a last-minute draft of the deal and demanded the support of other European leaders.
Ms Merkel still needs to complete that deal at another summit at the end of this week. If her party performs poorly on Sunday, she will go into that meeting weakened.
The meetings and demonstrations came as thousands of migrants have massed in muddy camps in the Greek border town of Idomeni after countries across the Balkans closed their borders.