BERLIN (Reuters) - The parties in Germany’s ruling coalition on Thursday reached agreement on a package of measures to deal with asylum-seekers who have already registered in other European Union states, and vowed to push ahead with an immigration law before year’s end.

The two-page agreement, reached after a short meeting at the historic Reichstag building, ends a dispute that had threatened to bring down Chancellor Angela Merkel’s ‘grand coalition’ just months after it took power, and left the four-term leader politically weakened.

But the debate has left lingering resentments in what was already a fragile coalition brokered by Merkel after she failed to forge an alliance with two smaller parties.

Interior Minister Horst Seehofer, leader of the Bavarian Christian Social Union (CSU), had triggered the crisis when he threatened to defy Merkel and turn back at the German border the small number of asylum seekers - a maximum of five people a day - who turn up after registering in other EU states.

The parties agreed to speed up the process of returning migrants who have applied for asylum in other EU states to those countries, as mandated by current EU law, but only if agreements were in place with the country where they first registered.

Full implementation would require signing deals with Italy and other countries that have been unwilling to take back migrants.

Social Democrats hailed the agreement as a win for their party, and criticized conservatives for what Finance Minister Olaf Scholz called the “summer theater” of the last weeks.

While the agreement averts the collapse of Merkel’s government and keeps her conservative bloc from splintering apart, the episode highlighted the fragility of the German government and raised the prospect of further disputes.

Seehofer told reporters he was “extremely satisfied” with the deal despite having to back off his call for border zone transit centers.

German Chancellor Angela Merkel, Finance Minister Olaf Scholz and German Interior Minister Horst Seehofer attend a budget debate at the lower house of parliament Bundestag in Berlin, Germany, July 4, 2018. REUTERS/Hannibal Hanschke

The agreement calls for asylum-seekers registered in other countries to be processed within 48 hours in police facilities, not separate transit centers, if they cannot be transported to the Munich airport to be returned to the country where they first applied for asylum.

Andrea Nahles, leader of the center-left Social Democrats (SPD), stressed the agreement would not involve creation of any transit centers or unilateral action by Germany. The SPD had warned such centers could be seen as internment camps.

Nahles told broadcaster ZDF the deal would not require any legal changes, and said it was up to Seehofer’s ministry, which oversees the border police, to accelerate the asylum process.

“I want to be very clear that we did not agree to some kind of a compromise. Instead we drafted a new proposal that includes reasonable solutions, and the CDU/CSU has performed a piece of theater in the last three weeks that was unworthy of this country, our country,” Nahles said.

Annegret Kramp-Karrenbauer, general secretary of Merkel’s Christian Democrats (CDU), said the deal laid the groundwork for a more unified approach on migration.

“With this, the entire coalition has committed to the goal to order, control and limit migration,” she said. “This agreement makes it possible that our migration policy is effective, that it remains humane and that it will succeed.”

As the agreement was reached, a new poll conducted for broadcaster ARD showed broad public frustration over the issue.

Nearly three-quarters of those surveyed said Seehofer had weakened German conservatives through his brinkmanship, and 78 percent said they were unhappy with the coalition’s work.

Fifty-six percent of Germans felt too much focus was being put on migration, to the detriment of other issues.

Annual migrant arrivals have dropped sharply after peaking in 2015 at over one million people, many of them fleeing Syria’s war and therefore entitled to asylum.

In 2017, a total of 15,414 people applied for asylum at German borders, with 1,740 of those applications made at the German-Austrian border - or around 4.7 per day, according to data from Seehofer’s ministry provided to Left party lawmakers.

Some in the SPD have accused Seehofer of sparking the coalition crisis to corral right-wing voters ahead of the Bavarian state election in October, after hemorrhaging a million voters to the anti-immigrant Alternative for Germany in the national election last September.

Seehofer and Austrian Chancellor Sebastian Kurz met in Vienna on Thursday and said they would discuss with Italy how to shut the migration route into Europe across the Mediterranean.