Fractious European leaders argued into the early hours on Friday over how to handle over a migrant crisis in the Mediterranean, agreeing a plan to share out the care of desperate people fleeing war and poverty in North Africa and the Middle East.
Determined not to be dragged into negotiations over Greece's debt debacle at their summit in Brussels, leaders instead found themselves sparring for seven hours about whether to take in 40,000 Syrian and Eritrean asylum seekers now in Italy and Greece and another 20,000 people currently outside the EU.
They eventually agreed a voluntary scheme, sticking to the 60,000 number but granted an exclusion for Hungary, which earlier described the plan as absurd, as well as for Bulgaria, one of the EU's poorest countries.
"It was a very intensive debate," German Chancellor Angela Merkel told reporters after the meeting ended, describing the migrant crisis "as the biggest challenge I have seen in European affairs in my time as chancellor".
That is a striking statement considering the euro zone debt crisis and confrontation with Russia during her decade in power.
Expressing his frustration, Commission President Jean-Claude Juncker described the plan as one of "modest ambition" and said at one point in the meeting he had told EU leaders "I don't give a damn" about objections to the plan's underlying methodology.
"We have to find out if the system works. It doesn't matter if it is voluntary or mandatory, it is whether it can help 60,000 refugees," Juncker told a news conference in the early hours of Friday.
However, the EU's chief executive had been hoping to set a precedent for Europe-wide action that limited national opt-outs.
During the summit dinner, Italian Prime Minister Matteo Renzi rebuked his fellow leaders for their reluctance to support a plan that was meant as an emergency response to the tragedy of 2,000 migrant deaths in the Mediterranean year but has been overshadowed by divisions, particularly in eastern Europe.
"If we think Europe is only about budgets, it is not the Europe we thought of in 1957 in Rome," Renzi said, referring to the European Union's founding treaty.
The summit became so tense that a speech by British Prime Minister David Cameron served as an interlude to cool tempers, with the much awaited address to pitch for a new deal for Britain in the European Union reduced to barely 10 minutes.
The mood was a long way from the unity showed by EU ministers in April immediately after the deaths of 900 migrants off the Libyan coast in a single weekend.
While the political deal was a breakthrough, implementing the plan still faces hurdles. The criteria to share migrants among member states must be decided by the end of July. Such factors as the size of a member state's economy and population must be considered.
"There's much, much more argument to come," said one senior EU diplomat. "I don't yet see the full way forward."
The criteria system replaces unpopular proposals for mandatory quotas on each country, which Poland, the Czech Republic, Slovakia, Hungary and others fought against, arguing their ex-Communist economies still lacked the capacity to cope.
The debate has also strained the EU's commitment to its Schengen agreement on passport-free travel.
This week, Austria threatened to reimpose controls on its border with Hungary and Britain called for more security around the French port of Calais. Britain and Spain want a bigger focus on returning migrants to countries of origin.