Time is running out for Angela Merkel. The term Mexit is worming its way into Germany’s political vocabulary, because the idea of Merkel’s departure after a decade in power is no longer unthinkable. Having held together the European Union through the Greek debt crisis and Russia’s war against Ukraine, Merkel is fighting for her own survival as the undisputed leader of Germany—and a united Europe.

Even as the German chancellor sat up with Turkish Prime Minister Ahmet Davutoglu Sunday night hammering out a grand bargain on Europe’s refugee crisis, the first results from Hessian municipal elections were coming in: The right-wing populist Alternative for Germany party was surging into the double digits, including in the country’s most international city, Frankfurt.

German television has dubbed March 13 “Super Sunday” because regional elections in three states are being viewed as a referendum on Merkel’s open-door refugee policy, which brought in more than 1 million asylum-seekers in 2015. Recent polls show the upstart Alternative for Germany rearranging the electoral calculus as it siphons conservative voters disappointed with Merkel’s Christian Democratic Union. To help stem the flow of migrants, the chancellor is coddling and cajoling Turkey, the main transit country for refugees heading to Europe from the Middle East’s war zones. Her outreach, though, has the rest of Europe on edge.

Merkel’s struggle is filled with such contradictions. Restoring passport-free travel among European countries means making the external EU border virtually impenetrable. As the chancellor demonstrates leadership in seeking a transnational solution, other EU leaders are reluctant to follow her—not just because of Germany’s history as a hegemon, but because Merkel is suspected of playing her own game. Perhaps most preposterous is a new plan to reward Ankara’s cooperation on border control by reinvigorating Turkey’s stalled bid to join the European Union.

At a summit in Brussels on Monday, the European Union agreed to study a Turkish offer to take back all “irregular migrants”—as people without proper documentation are known in Eurocratese—in exchange for a hefty set of concessions: For every Syrian refugee returned to Turkey, another Syrian from a Turkish refugee camp will be resettled in the European Union; 3 billion euros in EU aid to care for Syrian refugees in Turkey, in addition to an already promised 3 billion euros; the lifting of EU visa requirements for Turkish citizens this summer; and accelerated talks on EU membership for Turkey. In other words, refugees paying people-smugglers their last savings for the dangerous sea passage to Greece would go to the back of the line to go to Europe, while those sitting tight in camps would be at the front. About 2.7 million Syrian refugees are living in Turkey, many of whom see a brighter future in the European Union.

The Turkish initiative came as a surprise to most of the assembled EU leaders. Davutoglu had presented the demands to Merkel the night before at a meeting that reportedly lasted more than five hours. Although the chancellor later denied any involvement in the Turkish proposal, she couldn’t dispel the impression in Brussels that she had somehow been behind it.

What’s indisputable is that Merkel has been actively seeking Turkey’s help since the fall, when unprecedented numbers of migrants streamed into Germany after she accepted thousands of refugees stranded in Hungary. Merkel publicly made the case that if the 28 EU countries worked in concert, they wouldn’t need to close their internal borders and could comfortably take in however many Syrians fleeing that country’s civil war. At the same time, she set about trying to convince Turkish President Recep Tayyip Erdogan to stop the refugee trek at the source.

With the same persistence that she had pursued a cease-fire in Ukraine with Russian President Vladimir Putin, Merkel turned to Erdogan. The no-nonsense daughter of a Lutheran pastor was turned off by the two leaders’ machoism and vanity. But just as she recognized that Ukraine was a matter of war and peace in Europe, Merkel understood that no solution to the refugee crisis could exclude Turkey.

Photographs from an October meeting in Istanbul showed Erdogan and Merkel sitting side by side in gold thrones like a king and queen. Not only was the chancellor mocked as playing Erdogan’s “favorite lady-in-waiting,” she faced criticism for being instrumentalized by the Turkish president just before parliamentary elections. In November, the European Union and Turkey agreed on a “joint action plan” that promised Ankara 3 billion euros to improve the plight of Syrian refugees in return for better EU relations. The leaked minutes of a conversation between Erdogan and EU executives cited the Turkish president demanding twice as much money and threatening to send busloads of refugees over the European Union’s land borders if he didn’t get his way.

Merkel knew whom she was dealing with. In January, she invited Davutoglu’s Cabinet to Berlin for the first-ever intergovernmental consultations between the two countries. Less than a month later, Merkel and Erdogan caught NATO off guard by suggesting that the alliance could supply ships to patrol the waters between Turkey and Greece to stop human traffickers.

Erdogan was isolated after shooting down a Russian warplane following Putin’s entry into the Syrian civil war on the side of Turkey’s rival, Syrian President Bashar al-Assad. NATO wasn’t interested in getting involved in Erdogan’s self-inflicted dispute with the Kremlin. The Turkish military’s campaign against Kurdish fighters—the West’s most reliable allies in Syria—complicated matters even more. The refugee crisis presented Erdogan with a way out of his quandary. Attention from NATO and EU are making his loneliness go away, although his style of rule hasn’t changed in the least.

Over the weekend, Turkish authorities took control over the opposition Zaman newspaper and fired rubber bullets on female demonstrators protesting violence against women. After Monday’s summit, conservatives in Merkel’s own party railed against making too many concessions to Turkey, while human-rights groups and aid organizations criticized the new deal for its treatment of refugees risking their lives at sea.

In Brussels, Merkel downplayed the prospects for Turkey’s speedy entry into the European Union but added that “very close cooperation with Turkey is in our geopolitical interest”—unusual words for a German chancellor.

At this point in Merkel’s career, solving the refugee crisis is about more than just winning elections. In a live television interview in February, she called it the “most difficult problem of my chancellorship.” Unlike most of her other EU colleagues, Merkel is perfectly aware of the moment’s historical significance.

Her dilemma is whether the European values she champions end at Europe’s borders.

Read more of Slate’s coverage of the European migrant crisis.