On the face of it Angela Merkel has pulled off the compromise of her career.
She has quelled the mutiny that threatened to destroy her coalition government. And, it seems, pacified her rebellious interior minister, who was still raging as he went into last-ditch emergency talks last night.
Horst Seehofer, who also leads Mrs Merkel's Bavarian coalition partners, had snarled that he wasn't going to be thrown out by the woman he had put in power.
Later in the night he emerged beaming and triumphant to announce they had cut a deal.
But this is no victory for Angela Merkel.
The row, and the subsequent solution, have exposed the frailty of her position and may surprise those who still venerate the German chancellor as a defender of liberal values and open borders.
Why the political crisis?
The number of people seeking asylum in Germany has fallen sharply since the refugee crisis of 2015.
Yet the row that has dominated Mrs Merkel's every waking hour for weeks now has focused not on the integration of the million or so people who are already trying to make new lives in Germany, but on the rather quiet border itself.
More specifically, on what to do with the relatively small number of people who arrive there, having already registered or sought asylum in another EU country first.
The deal announced late on Monday night is short on detail, but Mrs Merkel appears to have reincarnated an idea raised during her previous administration: transit centres that are located inside the German border but, much like airports, are not technically on German soil.
From here migrants can be repatriated to the EU country where they first arrived.
The compromise only works if a bilateral agreement exists with those countries. If there isn't one, then - the leaders agreed - people will simply be turned away at the Austrian border, subject to an agreement with the Austrian government.
Is the crisis over?
The Austrian government does not seem terribly impressed with the solution and has, in turn, announced plans to "protect" Austria's southern border.
And it won't be long before the infighting breaks out again in Germany's troubled coalition.
Mrs Merkel is gambling on her centre-left partner, the Social Democrat SPD, accepting the deal - although they have opposed such transit centres in the past.
More from Jenny:
Last night the party leaders reacted relatively calmly.
Because if one thing trumps an illiberal migration policy for the SPD, it is the terrifying spectre of fresh elections. The SPD leadership cannot afford to let the coalition collapse. But its youth wing, which never wanted this alliance, is furious. As are some of its MPs.
It's tempting to wonder why Mrs Merkel did not just accept Mr Seehofer's initial offer of resignation last night.
She must have been itching to sack him ever since his first threat two weeks ago to act alone and start turning people away at the border. After all, she had the support of her party leadership and polls suggest that the majority of Germans prefer her European solution to his unilateral one.
But reports suggest that the mood among some of her MPs has soured. They are worried.
It's not just in pre-election Bavaria that anti-migrant rhetoric has borne fruit.
When the leaders of the far-right Alternative for Germany (AfD) crowed on Tuesday that they were "hunting the union, driving it before us" they were not entirely wrong in claiming triumph over the CDU and CSU.
Mrs Merkel has failed to achieve her original dream - a Europe that would truly share the responsibility for sheltering asylum seekers.
At last week's summit of EU leaders she thrashed out a much tougher policy, working alongside populist governments and other leaders who cherish national interests above those of the European Union.
Exhausted and embattled, Angela Merkel is having to adapt to a changed Europe.