– Chancellor Angela Merkel avoided the breakup of her government on Monday, emerging from an immigration fight with her coalition intact but fragile.

A clash that lasted weeks ended in an uneasy truce late Monday when Merkel and her party, the Christian Democrats (CDU), reached a compromise on Germany's immigration policy with partner Christian Social Union (CSU). Interior Minister and CSU leader Horst Seehofer backed off his threat to resign in protest and potentially bring down the government with him. A hard-line stance on immigration and criticism of Merkel's decision to welcome nearly a million migrants in 2015 have been part of the CSU's political strategy ahead of regional elections in the fall.

Merkel was widely seen here as handling the rebellion well. "She will prove to be a stable lighthouse in a tumultuous sea," said Nils Diederich, a political science professor at the Free University Berlin.

But the internal turbulence has preoccupied her at a time when Germany is reckoning with far bigger international challenges, especially the growing acrimony between Berlin and the U.S.

And the problems within her government are unlikely to go away: Relations between Merkel's CDU and its Bavarian sister have been badly strained, and the CSU itself is now riven by competing factions. That will make it difficult for her to return Germany to the relatively stable state for which it had long been known during her 13-year tenure.

Merkel and Seehofer reached this compromise:

At the German-Austrian border, the deal proposes new screening to "prevent asylum seekers whose asylum procedures are the responsibility of other E.U. countries from entering the country." A network of "transit centers" would serve as central processing points from which ineligible migrants would then be sent back to relevant countries, but only if those countries consent. If they do not agree, Germany's rejected migrants would be sent to Austria, "on the basis of an agreement."