BERLIN — Two days after pulling her government back from the brink by agreeing to set up transit camps for migrants at the border — and to eventually turn some of them away — Chancellor Angela Merkel is working to keep the deal from falling apart.

She and her interior minister have critical meetings Thursday with the leaders of Austria and Hungary, who must agree to take back some of the migrants in order to make the deal Ms. Merkel struck with the rebellious Bavarian partners in her own government.

Those leaders already criticized Ms. Merkel for her welcoming stance in 2015, when hundreds of thousands of people fleeing conflicts in Afghanistan, Syria and elsewhere flooded into Europe. So it is unclear if Austria and Hungary will go along with taking in migrants that Germany turns away.

Those decisions will be important in keeping her three-party coalition intact. Although the conservatives in her coalition have signed onto the deal, the other partner, the center-left Social Democratic Party, has expressed reservations about setting up “transit camps,” especially if other countries won’t take the migrants back and they are left in limbo.