The compromise came after lawmakers from both conservative parties in the German coalition urged the Chancellor and her interior minister on Monday to resolve the dispute over migrant policy that has thrown her three-month-old government into disarray.
"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 on leaving the CDU's Berlin headquarters.
The centre-left Social Democrats, another partner in the coalition, must also accept the deal along with neighbouring Austria.
The deal also faces a potential challenge from the European Union.
Under the German deal, migrants who have already applied for asylum in other European Union countries will be held in transit centers on the German border with Austria while Berlin negotiates bilateral accords for their return.
Sebastian Kurz is Austria's current chancellor.
Ms Merkel would have hoped she had put the crisis that threatened to bring down her government behind her when she hammered out the last-minute compromise with Horst Seehofer, her rebellious interior minister, on Monday night.
Germany's political crisis is the latest sign of a growing divide across the European Union between those who want to maintain open borders and those who want to restrict the number of migrants entering the bloc.
To politically survive, Merkel could attempt a minority government, seek a new coalition partner in the ecologist Greens or pro-business Free Democrats, or orchestrate a no-confidence vote in parliament that could trigger new elections.
The flashpoint issue was Seehofer's demand to order German border police to immediately turn back all asylum seekers already registered elsewhere in the European Union, and his threat to do so against Merkel's wishes.
It is the impending Bavarian state election in October that forced Mr. Seehofer's hand in seeking a confrontation on the migration issue. He insisted the CSU doesn't want to break up the conservative partnership. But a Forsa poll on Tuesday showed a majority of Germans to be unhappy about the agreement.
Before the refugee crisis of 2015, Seehofer was mainly concerned with regional pet projects tolerated by Merkel, such as rewarding mothers who raise young children at home with state benefits and charging foreign motorists for using Germany's Autobahn.
Since then, more than one million people have arrived in Germany, while Merkel's governments have repeatedly tightened immigration and asylum laws.
Nevertheless, the anti-refugee, anti-Islam Alternative for Germany (AfD) entered parliament for the first time previous year, leading to months of paralysis while Merkel struggled to put together a workable coalition.
German Chancellor Angela Markel on Monday balked on her signature immigration policies in a bid to stay in power, agreeing to create border camps for migrants and enforce tighter border control.