Chancellor Angela Merkel’s ruling coalition caught a breather Sunday as its main parties stemmed a surge by Germany’s far-right populists in two elections in the former communist east.

The euroskeptic, anti-immigration Alternative for Germany (AfD),trailed the incumbent Social Democrats by about 4 percentage points in the eastern state of Brandenburg, according to official results. In neighboring Saxony, Merkel’s Christian Democrats led the AfD by around the same margin.

The narrow victories in the two states may for now stave off a deeper political crisis in the 17-month-old governing coalition that had been bickering over issues from environment to gender and wealth gaps and suffered heavy losses in EU elections earlier this year. But at the same time, both coalition parties said the results showed some of their shortcomings.

“The SPD but also the CDU must focus much more on the East,” SPD co-Chair Manuela Schwesig told ARD television Monday.

Annegret Kramp-Karrenbauer, the CDU’s national leader, acknowledged that the party had not addressed some of the problems afflicting Germany “as elegantly” as it should have, which was also reflected in the regional election results.

“We see that people want answers for the future, they want things to be tackled in the government,” Kramp-Karrenbauer said on ARD television. “That is exactly my task and that’s what we will do in coming weeks in a very focused way.”

Indeed, the stiff challenge from a protest party that didn’t exist before 2013 is a wake-up call to Germany’s two main parties just as Europe’s largest nation teeters on the brink of a recession.

“Good that they’re not ahead, but better that they can’t repeat these results,” Finance Minister Olaf Scholz of the SPD said on local TV. “It’s the duty of all of us to ensure the AfD becomes weaker again.”

Sunday’s result may have been as much a vote against extremism as it was for Germany’s mainstream parties, which have continually lost ground to the right wing and to the Greens in recent years.

“This was a very strong signal against the AfD, people didn’t want the AfD to be the strongest party,” said SPD Secretary-General Lars Klingbeil. “We have very mixed feelings, I can say that openly.”

Merkel’s ruling coalition has been plagued by infighting and a poor showing Sunday could have further pushed the SPD, the junior coalition partner, to eventually leave government.

“It could have been worse,” Carsten Nickel, analyst at Teneo Intelligence in London, wrote in response to a query. “But there is no denying that the SPD continues to die a slow death while the CDU lacks any idea for the post-Merkel world.”

Despite nearly a decade of consistent economic growth, there has been growing discontent with Merkel and the ruling parties, particularly in the former communist east, which has undergone decades of social and economic change. The region now faces the loss of tens of thousands of jobs from Germany’s plans to phase out coal mining by 2038.

In the run-up to the election the Merkel administration promised to transfer civil servant jobs to the east, and earmarked €40 billion to help exit coal by 2038.

Even if the AfD had won, it would unlikely have formed or participated in a government, as no other party is willing to partner with it.