The EU and Turkey have reached a deal on the migrant crisis, which will see migrants returned to Turkey in exchange for aid and political concessions.
Under the plan, from midnight Sunday migrants arriving in Greece will be sent back to Turkey if their asylum claim is rejected.
In return, EU countries will resettle Syrian migrants living in Turkey.
EU leaders have welcomed the agreement but German Chancellor Angela Merkel warned of legal challenges to come.
Some of the initial concessions offered to Turkey have been watered down and some EU members expressed disquiet over Turkey's human rights record.
Despite this Turkish Prime Minister Ahmet Davutoglu said it was a "historic" day.
"We today realised that Turkey and the EU have the same destiny, the same challenges and the same future."
European Council President Donald Tusk said there had been unanimous agreement between Turkey and the 28 EU members.
It is hoped the plan will deter people from taking the often dangerous sea crossing from Turkey to Greece.
Analysis: BBC's Chris Morris in Brussels
Scepticism hangs heavy in the air about a host of legal issues, and about whether the agreement can actually work in practice.
The idea at the heart of the deal - sending virtually all irregular migrants back to Turkey from the Greek islands - is the most controversial.
European leaders insist that everything will be in compliance with the law.
"It excludes any kind of collective expulsions," emphasised European Council President Donald Tusk.
But Amnesty International has accused the EU of "turning its back on a global refugee crisis, and wilfully ignoring its international obligations".
The UN refugee agency (UNHCR) will take part in the scheme, but it is clearly uncomfortable with what has been agreed.
Mr Tusk stressed the deal was no "silver bullet" and was just one part of the EU's response to a crisis that has sharply divided the bloc's members.
Mrs Merkel said she was satisfied but added "I have no illusions that what we agreed today will be accompanied by further setbacks".
British Prime Minister David Cameron has welcomed the deal, saying it could "significantly" reduce numbers of migrants crossing the eastern Mediterranean to enter Greece by boat.
Key points from the agreement
- Returns: All "irregular migrants" crossing from Turkey into Greece from 20 March will be sent back. Each arrival will be individually assessed by the Greek authorities.
- One-for-one: For each migrant returned to Turkey, a Syrian migrant will be resettled in the EU. Priority will be given to those who have not tried to illegally enter the EU and the number is capped at 72,000.
- Visa restrictions: Turkish nationals should have access to the Schengen passport-free zone by June. This will not apply to non-Schengen countries like Britain.
- Financial aid: The EU is to speed up the allocation of €3 bn ($3.3 bn; £2.3 bn) in aid to Turkey to help migrants.
- Turkey EU membership: Both sides agreed to "re-energise" Turkey's bid to join the European bloc, with talks due by July.
The UN warned that Greece's capacity to assess asylum claims needed to be strengthened for the deal. Implementation was "crucial", the organisation said.
But rights group Amnesty International was scathing, calling the agreement a "dark day for humanity".
An EU source told the BBC up to 72,000 Syrian migrants living in Turkey would be settled in the EU under the agreement.
They added that the mechanism would be abandoned if the numbers returned to Turkey exceeded that figure.
Also on Friday, Turkish officials said they detained almost 1,800 migrants and 16 people smugglers.
The operation was part of efforts to stop migrants reaching the Greek island of Lesbos, Reuters reported.
Since January 2015, a million migrants and refugees have entered the EU by boat from Turkey to Greece. More than 132,000 have arrived this year alone.
Tens of thousands are now stuck in Greece as their route north has been blocked.
Greek Interior Minister Panagiotis Kouroublis has compared conditions at the Idomeni camp, on the border with Macedonia, to a Nazi concentration camp.
A note on terminology: The BBC uses the term migrant to refer to all people on the move who have yet to complete the legal process of claiming asylum. This group includes people fleeing war-torn countries such as Syria, who are likely to be granted refugee status, as well as people who are seeking jobs and better lives, who governments are likely to rule are economic migrants.