German Chancellor Angela Merkel has reached a deal on immigration to end a row that threatened to break up her four-month-old coalition government.
Interior Minister Horst Seehofer has now dropped his threat to resign after hours of talks.
Mrs Merkel agreed to tighten controls at the Austrian border to stop people who have applied for asylum in other EU countries from entering Germany.
Transit centres will be set up to hold them until they can be sent back.
Mrs Merkel described the deal as a good compromise after tough negotiations.
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,” he told reporters as he was leaving the CDU’s Berlin headquarters.
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.
Top CSU officials had said they wanted to stay in government with Mrs Merkel’s CDU.
Mrs Merkel got backing from both parties at a parliamentary meeting on Monday. Mr Seehofer was not there.
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”.
- Gruelling migration talks end in draw
- Chancellor Merkel: Germany’s shrewd survivor
- Could the migration crisis finish the EU?
The two centre-right parties share power with the centre-left Social Democrats (SPD), who have yet to give their backing to the last-minute compromise.
SPD leader Andrea Nahles had already 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 were 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.
Germany migrants: Merkel averts coalition government split