Germany’s Interior Minister Horst Seehofer says he will not resign, after hours of crisis talks with Chancellor Angela Merkel.
He said the two conservative parties in the governing coalition had agreed on how to prevent illegal migration across the border from Austria.
He had earlier threatened to quit but said tighter border controls had been agreed.
Mrs Merkel says a good compromise was found, Reuters news agency reports.
Mr Seehofer leads the Christian Social Union (CSU), the Bavarian sister party of Mrs Merkel’s Christian Democrats (CDU).
“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,” Mr Seehofer told reporters as he was leaving the CDU’s Berlin headquarters.
Mr Seehofer was demanding a right to turn irregular migrants away at Bavaria’s border but Mrs Merkel defended a deal reached with the EU.
Top CSU officials had said they wanted to stay in government with Mrs Merkel’s CDU.
Coalition’s ‘common destiny’
Mrs Merkel got backing from both the CDU and CSU at a parliamentary meeting on Monday. Mr Seehofer was not there.
Alexander Dobrindt, leader of the CSU parliamentary group, said “a common destiny proves its worth only when it is challenged”. He praised 70 years of unity between the two centre-right parties, German media reported.
Bavaria’s CSU Prime Minister, Markus Söder, said “we’re ready for compromises” and “for us now there is no exit from the government”.
The BBC’s Jenny Hill in Berlin says Mr Seehofer may have overplayed his hand by issuing his ultimatum, only for Mrs Merkel to return from Brussels on Friday with an EU-wide strategy and bilateral agreements with more than 10 countries.
Opinion polls suggest that, in the event of a fresh election, the SPD would not profit from the CDU-CSU rift over migration.
But SPD leader Andrea Nahles warned that “my patience has worn thin”. “We want a humanitarian, but also realistic, migration policy,” she told a news conference.
How did the events unfold?
On Sunday evening, the CDU passed a resolution supporting Mrs Merkel’s position on migration. CDU General Secretary Annegret Kramp-Karrenbauer said the party believed a European solution was necessary.
Then reports emerged from the CSU that Mr Seehofer had offered to step down both as party leader and interior minister.
Mr Seehofer complained that he had held a “conversation with no effect” with Mrs Merkel on Saturday.
Senior CSU figures, including Mr Dobrindt, immediately tried to persuade Mr Seehofer not to quit. Then early on Monday Mr Seehofer announced he had agreed to hold final talks with the CDU as a “concession”.
What did Mrs Merkel negotiate with the EU?
Mrs Merkel stayed up with EU leaders until dawn on Friday to clinch a new deal on migrants.
She said Greece and Spain had agreed to take back migrants stopped at the Bavarian-Austrian border who are proven to have entered their countries first – a move she hoped would allay Mr Seehofer’s concerns.
“The sum of all we’ve agreed is equivalent to what the CSU wants,” she said.
However, Italy – where most irregular migrants arrive – does not want to take back migrants who reach Germany.
The divisions within the German government over the issue are also being played out in other EU countries, and three countries later said they were not part of the German deal: the Czech Republic, Hungary and Poland.