German voters on Sunday appeared to send a message to Chancellor Angela Merkel: Close the door on migrants.

Her center-right Christian Democratic Party suffered universal setbacks in local elections — in a vote widely seen as a referendum on Merkel’s humanitarian stance allowing vast waves of migrants to cross German borders.

The upstart Alternative for Germany (AfD) party, a populist force that campaigned on an anti-migrant, anti-Merkel platform — and which drew support from the left as well as the right — scored big gains. It landed 24.4 percent of the vote in one of the three states that went to the ballot box, according to projections based on exit polls produced for the German public broadcaster ARD.

[A right-wing party in Germany hopes to capitalize on anti-migrant anger]

The outcome amounted to a blow to Merkel just as the chancellor is set to fight this week for a new accord between the European Union and Turkey on the refugee crisis. It would stop the illegal flow of migrants across the Aegean Sea, but also compel reluctant European nations, including Germany, to take in more Syrian asylum seekers from Turkey.

Guido Wolf, lead candidate for the German Christian Democrats looks on during a press conference after Sunday’s state-level parliamentary elections. (Alexander Hassenstein/Getty Images)

At home, Merkel has already vowed to speed up deportations of migrants who are not fleeing war. In the past 12 months, more than a million migrants from the Middle East and beyond have sought sanctuary and jobs in Europe’s economic powerhouse. Yet in a sign that public tolerance may be growing thin, voter turnout was up Sunday, and above 70 percent in two of the states voting.

[As the route to Europe closes, migrants journey through grief]

“The results will probably further fuel the existing unease with Merkel within her own CDU,” said Carsten Nickel, senior vice president of Teneo Intelligence.

The CDU’s worst losses of the night came in Baden-Wuerttemberg, where her party was falling to 27 percent support — a record low. The CDU had held sway in the state for most of the post-World War II era, but ended the night down 12 percentage points from its last showing.

The CDU also lost ground — but less, about 3 percentage points — in the states of Rhineland-Palatinate and Saxony-Anhalt. Importantly, one of the CDU’s rising stars, Julia Klöckner, was failing in her bid to unseat the incumbent for Rhineland-Palatinate’s top job.

At the same time, the AfD — a party that sought to tap the anxiety of Germans over the wave of newcomers — made strong gains. The party drew voters to the polls who had rarely or never participated in elections. Projections showed it winning more than 24 percent in Saxony-Anhalt, located in the former East Germany where anti-migrant sentiment is running particularly high. The AfD also gained ground in the two other states, with preliminary results showing it won 12.6 percent of the vote in Rhineland-Palatinate and 15.1 percent in wealthy, heavily industrialized Baden-Wuerttemberg.

[Think Merkel isn’t in trouble? Look at these charts.]

Migrants stranded on Greece's border with Macedonia staged a protest on March 13, marching along muddy, waterlogged fields calling for the border to be opened. Men, women and children chanted "Merkel" as they waved their fists in the air. (Reuters)

Nevertheless, analysts predicted that Merkel, who has defended her plan to shelter war-torn refugees while weeding out economic migrants, probably would hold firm. She has the luxury of claiming that key local CDU politicians, including Klöckner, who failed on Sunday have criticized her refugee policy. They lost to opposition politicians who sometimes had been more supportive of the chancellor’s refugee policy than members of her own party.

“When it comes to the refugee crisis, Merkel might change her tone, but not her politics,” said Jürgen Falter, a political analyst at Mainz University. “She seems to be so utterly convinced of her strategy that I do not expect her to do anything different, unless her European partners force her to.“

Stephanie Kirchner contributed to this report.

Read more:

Europe’s harsh new message for migrants: ‘Do not come’

As ‘Jungle’ camp taken down, French police clash with desperate migrants

Most of the refugees stuck in Greece are now women and children

Today's coverage from Post correspondents around the world