BERLIN (Reuters) - German Chancellor Angela Merkel’s conservatives settled a row over migration that threatened to topple her fragile governing coalition late on Monday evening after talks with her rebellious interior minister led him to drop his threat to resign.

Emerging after five hours of talks, Horst Seehofer, leader of Bavaria’s Christian Social Union (CSU), told reporters he would remain in his post after a deal with Merkel’s Christian Democrats (CDU) that he said would stem illegal immigration.

“After intensive discussions between the CDU and CSU we have reached an agreement on how we can in future prevent illegal immigration on the border between Germany and Austria,” Seehofer said as he left the CDU’s Berlin headquarters.

The deal, which brought Merkel’s government to the brink of collapse just three months after it was formed, keeps her in office. But the woman who has dominated European politics for 12-1/2 years appears greatly diminished, raising questions over whether she will serve out her term.

The euro currency wobbled on several occasions during the weeks-long row, which stretched to breaking point a 70-year-old alliance between the two parties.

It was the latest aftershock from Merkel’s 2015 decision to open Germany’s borders to more than a million refugees from war in the Middle East and Africa.

That decision convulsed European politics, fueling the rise of anti-immigration parties including the far-right Alternative for Germany (AfD) party, which now threatens to unseat the CSU in October’s regional elections.

Under the deal migrants who have already applied for asylum in other European Union countries will be held in transit centers on the border while Germany negotiates bilateral deals for their return.

“SPIRIT OF PARTNERSHIP”

The transit centers, like ‘airside’ zones in international airports, will be regarded for immigration purposes as not being in Germany, making it easier to deport from them.

The compromise deal meant that Seehofer was able to hail tighter immigration controls, while Merkel was able to say that Germany adhered to EU rules and upheld freedom of movement within the bloc.

“The spirit of partnership in the European Union is preserved and at the same time an important step to order (has been taken), Merkel told reporters.

But the crisis, the latest of several rows over migration between the two parties, is another sign of the EU-wide divide between those who want to maintain open borders and those who want to restrict the number of migrants entering the bloc.

Slideshow ( 12 images )

Merkel’s CDU relies on the CSU to maintain power through a coalition. The center-left Social Democrats, another partner in the coalition, must also accept the deal along with neighboring Austria.