After months of acrimony, the European Union and Turkey reached a landmark deal on Friday to ease the migrant crisis and give Ankara concessions on better EU relations.

In a final meeting high on smiles, handshakes and backslapping, the 28 EU leaders and Turkish Prime Minister Ahmet Davutoglu sealed an agreement that will allow thousands of migrants to be sent back to Turkey as of Sunday, while Ankara will see fast-track procedures to get billions in aid to deal with refugees on their territory, unprecedented visa concessions for Turks to come to Europe and a re-energizing of their EU membership bid.

Davutoglu strode into the final joint session with the poise of a winner, happily shaking hands with German Chancellor Angela Merkel and getting an encouraging pat on the back from French President Francois Hollande.

"The deal with Turkey approved. All illegal migrants who reach Greece from Turkey starting March 20 will be returned," tweeted Czech Prime Minister Bohuslav Sobotka.

Davutoglu said Turkey's prime concern was the fate of almost 3 million Syrian refugees on its territory. At the same time, he was looking for unprecedented concessions to bring the EU's eastern neighbor closer to the bloc.

For the EU, the deal brought some closure to months of bitter infighting over how to deal with the migrant crisis, which would essentially see Europe outsource its refugee emergency to Turkey.

"For Turkey, the refugee issue is not an issue of bargaining, but values," Davutoglu told reporters earlier Friday, staking out the same moral ground that the EU has claimed throughout the crisis.

With more than 1 million migrants arriving in Europe over the past year, EU leaders were desperate to clinch a deal with Turkey and heal deep rifts within the bloc, while relieving the pressure on Greece, which has borne the brunt of arrivals.

The agreement would have clear commitments that the rights of legitimate refugees would be respected and treated according to international and EU law. Within a week, Turkish and EU officials would assess joint projects to help Syrian refugees in Turkey, after complaints that promised aid of $3.3 billion was too slow in coming.

Turkey would also be guaranteed that EU accession talks on budgetary issues could start before the summer.

In the Idomeni camp on the Greek-Macedonian border, Muhammad Hassan, a Syrian from the devastated city of Aleppo, was looking for relief from the talks in Brussels and wondered why a continent of 500 million people could not deal with the situation.

"Europe have only 1 million" migrants, Hassan said. "How come it's difficult?" he asked, comparing the EU to Lebanon, a nation of 5.9 million. "If a small country takes 3 million refugees and didn't talk, how about Europe? It's not difficult."

The conditions in Greece and the Idomeni camp were called intolerable by the Greek government on Friday. Interior Minister Panagiotis Kouroumplis compared the crowded tent city to a Nazi concentration camp, blaming the suffering on some European countries' closed border policies.

During a visit to Idomeni Friday, Kouroumplis said the situation was a result of closed borders by countries that refused to accept refugees.

More than 46,000 people are trapped in Greece, after Austria and a series of Balkan countries stopped letting through refugees who reach Greece from Turkey and want to go to Europe's prosperous heartland. Greece wants refugees to move from Idomeni to organized shelters.

The EU-Turkey plan would be operational despite concerns about Turkey's subpar asylum system and human rights abuses. Under it, the EU would pay to send new migrants arriving in Greece who don't qualify for asylum back to Turkey. For every Syrian returned, the EU would accept one Syrian refugee, for a target figure of 72,000 people to be distributed among European states.

Apart from easing visa restrictions, the EU will also offer Turkey — home to 2.7 million Syrian refugees — up to 6 billion euros ($6.6 billion) in aid, and faster EU membership talks.