COTTBUS, Germany — Germany’s far-right party made significant gains in elections in two of the country’s eastern states on Sunday, according to preliminary results, but it failed to surpass establishment parties to gain the biggest portion of the vote, as some had predicted.

Brandenburg, which surrounds the capital Berlin, and Saxony, on the country’s eastern border with Poland and a stronghold of support for the right-wing Alternative for Germany (AfD) Party, were voting to elect representatives for their state legislatures.

Although preliminary results released early Monday showed a surge in support for the right-wing party, it came in second in both states.

Angela Merkel’s center-right Christian Democratic Union won 32.1 percent of the vote in Saxony; AfD took 27.5 percent. The Social Democratic Party, the Christian Democrats’ center-left coalition partner in the national parliament, won 26.2 percent in Brandenburg; AfD took 23. 5 percent.

The results weren’t as bad for Germany’s traditional parties as they had feared, but still showed a significant shift to the far right, which drew out new voters in an election with greater-than-usual turnout. The drop in support could complicate their efforts to form a ruling coalition. The major parties having ruled out forming coalitions with the AfD. 

“One thing is clear from these results: The AfD came to stay,” Andreas Kalbitz, the AfD leader in Brandenburg, said at an election party. In recent days he acknowledged attending a neo-Nazi rally in Greece more than a decade ago after a leaked report in Der Spiegel. He said he had done so out of “curiosity.”

“Politics without us is no longer possible,” he said. The party won a similar proportion of the vote in federal elections in 2017.

It was the first vote for representatives in state-level parliaments in eastern Germany since Merkel opened Germany’s doors to more than a million refugees, many of them fleeing the civil war in Syria. While many Germans approved the decision, it has also caused a backlash. Immigration has become a rallying point for the AfD.

“Take your country back,” campaign banners read. 

The party also has tapped into resentment among the people of the former East Germany, which still suffers from higher unemployment and lower wages and pensions than the West, about 30 years after the country’s reunification.

But many of those voting said immigration was the most important issue for them.

Cottbus, Brandenburg’s second-largest city, lies 80 miles southeast of Berlin, in the heart of Germany’s coal region. At one polling site, a 50-year-old shop assistant and her husband said they cast their ballots for the AfD.

“We want our country to be open to the world, but only for people who respect our culture and way of life,” she said. “Being AfD doesn’t mean being Nazi. We are not Nazis.”

The couple declined to be named, saying they could be stigmatized for voting for the AfD.

Professor Hans Vorländer, director of the Mercator Forum for Migration and Democracy at the Dresden University of Technology, said the results were “primarily a win for the AfD, though they didn’t reach their goal to become the strongest party.”

A Christian Democratic loss in Saxony could have threatened the position of Merkel’s anointed successor, Annegret Kramp-Karrenbauer, at the national level, he said. 

Vorländer said the results didn’t necessarily show support for the major parties, but could reflect voters casting their ballots for them in an attempt to block the AfD.

Michael Keil, a 34-year-old business administration student voted for the Green Party, which made gains in Brandenburg and Saxony, despite traditionally struggling to sell its environmental message in a region that depends on coal and industry for jobs. 

“It’s important to vote to counter the AfD,” Keil said. He said people in the former East Germany have little experience of foreigners and “they just vote on fear.”

A majority in western Germany supported Merkel’s decision to open the country to largely Middle Eastern refugees in 2015, but a majority in the east opposed it.

“We have two party systems,” Vorländer said. “One for the East and one for the West.”

The left-wing Die Linke was previously the anti-establishment party in the East, he said, but now the AfD is filling that role. Exit polls showed Die Linke losing votes in Saxony and Brandenburg. 

Dietmar Bartsch, a representative for the party in the national parliament, called the results an “unprecedented disaster” for his party.

For the regions’ newest residents, it’s a worrying trajectory. Sayed Walid, a 25-year-old asylum seeker from Afghanistan who has lived in Cottbus for three years, said the growth in support for the AfD was a concern.

“If they win,” he said, “I don’t know what will happen to people like us, what the future of the country will be, what the reaction of the people will be.”