After nine hours of often stormy talks, EU leaders agreed to share out refugees arriving in the bloc on a voluntary basis and create "controlled centers" inside the European Union to process asylum requests.
They also agreed to share responsibility for migrants rescued at sea, a key demand of Italy's new prime minister, Giuseppe Conte.
"Italy is not alone anymore," he said.
Conte, whose government includes the anti-establishment 5-Star movement and far-right League, had earlier refused to endorse a summit text on security and trade until other leaders had pledged to help Italy manage Mediterranean arrivals.
Interior Minister Matteo Salvini, whose League party campaigned to bar migrants fleeing Africa and expel those already in Italy, said he was "satisfied and proud of our government's results in Brussels."
"Finally Europe has been forced to discuss an Italian proposal ... (and) finally Italy is no longer isolated and has returned to being a protagonist," he said in a statement.
The summit underscored how Europe's 2015 spike in immigration continues to haunt the bloc.
Although the traffic has slowed in recent years, there are still daily stories of disasters as migrants make the perilous crossing from Africa to Europe. The Libyan coastguard said around 100 were thought to have drowned off Tripoli on Friday.
United Nations aid agencies gave the EU deal a cautious welcome.
"We will welcome any outcome that leads to a more collaborative and harmonized approach to asylum, also one that has at its core and priority saving lives at sea," said Charlie Yaxley of the refugee agency UNHCR.
The EU summit took place in an atmosphere of political crisis, with Merkel under intense pressure at home to take a firmer stance on migration.
Speaking to reporters at 5 a.m., she said it was a good signal that leaders had been able to agree a common text, but acknowledged the bloc still had "a lot of work to do to bridge the different views."
French President Emmanuel Macron, who has sharply criticized Italy for refusing to allow a migrant rescue ship into its ports, said European cooperation had "won the day."
In a final statement full of convoluted language designed to appease the divergent views, the leaders agreed to restrict migrant moves within the bloc but made clear virtually all of their pledges would be carried out on a "voluntary basis" by member states.
They also agreed to tighten their external border and increase financing for Turkey, Morocco and other North African states to prevent migration to Europe.
Merkel's coalition partner, the Christian Social Union (CSU), which has threatened to shut Bavaria's border to migrants — something that could trigger the collapse of her three-month-old government as well as the EU's Schengen free-travel zone — gave the summit deal a cautious welcome.
CSU lawmaker Hans Michelbach told ARD television areas of the deal would be "difficult to implement" and that Merkel would have to discuss it with CSU leader, Horst Seehofer, in the coming days.
But he underlined the importance of the CSU's ties with Merkel's CDU: "We want to work together. The alliance with the CDU has absolute priority."
Diplomats described a tense, tortuous meeting with small groups of leaders huddled together in a desperate bid to break the deadlock and avert the humiliation of heading home without an agreement.
Early in the evening, Merkel and Conte set aside 45 minutes for a chat, only to break it off after 20 minutes when the Italian rejected the German leader's overtures, according to diplomats.
"It is so toxic. They go into the room, clash, storm out, go back again, clash again. With no end in sight," said one exasperated diplomat as dawn approached.
"It's pure politics driving this, emotions are flying as high as back in 2015," another EU diplomat said.
Fewer than 45,000 migrants have made it to the European Union this year, according to UN data, a sharp drop from 2015 when many thousands were entering on a daily basis.
But the political tremors are still being felt across Europe, with populist, anti-immigrant parties on the rise in many countries.
Ex-communist easterners, led by Poland and Hungary, are still refusing to accept a share of the new arrivals to alleviate the burden on countries such as Italy and Greece.
By Gabriela Baczynska, Noah Barkin and Richard Lough/Reuters
Reporting by Francesco Guarascio, Philip Blenkinsop, Robert-Jan Bartunek, Alissa de Carbonnel, Robin Emmott, Jan Strupczewski, Noah Barkin, Richard Lough, Jean-Baptiste Vey, Elizabeth Piper, Andreas Rinke, Peter Maushagen and Gabriela Baczynska; Writing by Noah Barkin and Gabriela Baczynska; editing by William Maclean, Robin Pomeroy, Richard Balmforth.
Every week, more than 2 million listeners tune into our broadcast and follow our digital coverage like this story, which is available to read for free thanks to charitable contributions from listeners like you. But less than 1% of our audience supports our program directly. From now through the end of the year, every gift will be matched dollar for dollar by a generous donor, which means your gift will help us unlock a $67,000 challenge match.
Will you join our growing list of loyal supporters and double your impact today?