EU leaders holding late-night talks in Brussels have agreed to relocate tens of thousands of migrants who have arrived in Italy and Greece.
Summit chairman Donald Tusk said 40,000 would be relocated to other EU states over the next two years.
However, there would be no mandatory quotas for each country.
The Greek debt crisis was also on the summit's agenda. Greece and its international creditors remain deadlocked after talks on Thursday.
Earlier, Mr Tusk called on EU member states to share the burden of the boat loads of illegal migrants who have crossed the Mediterranean.
'Modest' plan
New figures from the UN refugee agency UNHCR show that 63,000 migrants have arrived in Greece by sea this year and 62,000 in Italy.
"Leaders agreed that 40,000 persons in need will be relocated from Greece and Italy to other states over the next two years," Mr Tusk told reporters. "Interior ministers will finalise the scheme by the end of July."
Leaders also agreed to resettle another 20,000 refugees from outside the EU.
The BBC's Damian Grammaticas in Brussels said Hungary, which had seen thousands of migrants cross its border by land, and Bulgaria, one of the EU's poorest countries, had both been granted exemptions.
The UK has opted out of the scheme, while nations in eastern Europe refused to accept set quotas, so it will be only voluntary. This angered Italy's Prime Minister Matteo Renzi, who called the plan "modest".
Italy has sought more help from its EU partners to handle the boat loads of migrants.
The migrant crisis has been high on the agenda for the EU summit, which opened on Thursday.
The final day of the summit on Friday is due to focus on security issues, namely the Ukraine crisis and tensions with Russia.
The migrant situation is being fuelled by the many Syrians fleeing the civil war in their country.
More than three million refugees are being housed in countries on Syria's borders - far more than the EU has taken in.
But many thousands are also fleeing chaos, violence and dire poverty in Eritrea, Somalia and other countries of sub-Saharan Africa.
Saturday deadline
Meanwhile, the impasse in the Greek debt talks threatened to overshadow the summit, with two hours of unscheduled talks on Thursday.
Only once agreement on economic reforms is reached between Greece and its creditors - the European Commission, the European Central Bank (ECB) and the International Monetary Fund (IMF) - will the final €7.2bn tranche of bailout funds be released to Greece.
EU President Donald Tusk said European leaders are pushing for a weekend deadline for a deal to be reached, tweeting: "Another Eurosummit is not foreseen. Leaders expect the Eurogroup to conclude this process at their meeting on Saturday."
Cash-strapped Greece must make a €1.6bn (£1.1bn) IMF debt repayment by Tuesday or face default and a possible exit from the euro.
On Thursday, a meeting of eurozone finance ministers also broke up without progress on the issue.
It was the fourth time in a week that the Eurogroup had met in an attempt to prevent a Greek debt default. They will meet again on Saturday.
German Chancellor Angela Merkel said that meeting would be "decisive" in finding a solution.
IMF head Christine Lagarde said lenders had been presented with a counter-proposal by the Greek parties "at the last hour" on Thursday and needed more time to assess it, Reuters reported.
Also during Thursday's talks, UK Prime Minister David Cameron outlined his plans to renegotiate the terms of Britain's membership of the EU.
Mr Tusk said EU leaders should consider British concerns but "only in a way that is safe for all of Europe".
- BBC