The European Union and Turkey agreed Friday on a deal that all sides hope will relieve Europe's worst refugee crisis since World War II.

European Council President Donald Tusk and Turkish Prime Minister Ahmet Davutoglu called it a "landmark" agreement. The prime minister said Friday was a "historic day" for Turkey and the EU.

"We today realized that Turkey and the EU have the same destiny, the same challenges and the same future," Davutoglu said.

The deal takes effect Sunday. All migrants who illegally enter Greece from Syria and elsewhere — including those already in Turkey — will be sent to Turkey after they are registered and their claims for asylum in Europe are considered.

In exchange, thousands of refugees who fled to Turkey and legally sought asylum will be resettled equally across the 28 EU members.

Migrants walk along a road from the village of Cha FILE - Migrants walk along a road from the village of Chamilo to the migrant camp at the village of Idomeni, near the Greek-Macedonian border, Greece, March 15, 2016. FILE - Migrants walk along a road from the village of Chamilo to the migrant camp at the village of Idomeni, near the Greek-Macedonian border, Greece, March 15, 2016.

Turkey already shelters nearly 3 million Syrian refugees. It will get EU financial help to deal with the refugee crisis — it will eventually double to about $6.7 billion — along with quicker EU membership talks and visa-free travel for Turkish citizens across the EU by the end of June, if Turkey meets a number of preconditions.

Tusk warned that the deal, by itself, would not solve Europe’s migrant crisis.

“Some may think this agreement is a silver bullet, but the reality is more complex," he said. "It is just one pillar of the comprehensive European strategy and can only work if the other pillars are implemented.”

Those other pillars include strengthening the EU’s external borders, keeping a well-traveled migrant route across the western Balkans closed and returning to the open-borders Schengen system internally.

Turkey has a shaky human rights record, and some human rights groups said the plan uses people looking for refuge from war, poverty and terrorism as political pawns.

Amnesty International slammed the agreement, saying Turkey was not a safe country for refugees or migrants, and that the process of returning asylum seekers would inevitably be "flawed, illegal and immoral.”

The U.N. refugee agency said it was vital that all sides respect international and European law.

"How this plan is to be implemented is ... going to be crucial. Ultimately, the response must be about addressing the compelling needs of individuals fleeing war and persecution. Refugees need protection, not rejection," the UNHCR said in a statement.

A woman stands in a crowd beside the railway track A woman stands in a crowd beside the railway tracks as a train passes beside a refugee camp where thousands of refugees are waiting to be allowed to cross the border into Macedonia in the northern Greek border station of Idomeni, Thursday, March 3, 2016. A woman stands in a crowd beside the railway tracks as a train passes beside a refugee camp where thousands of refugees are waiting to be allowed to cross the border into Macedonia in the northern Greek border station of Idomeni, Thursday, March 3, 2016.

Even some EU leaders who signed off on the plan said they were not entirely happy with it.

Lithuanian President Dalia Grybauskaite said the proposal "is on the edge of international law" and might be hard to implement. Belgian Prime Minister Charles Michel accused Turkey of blackmail.

But Europe has been struggling with the refugee crisis for months, and no one has come up with a solution on which everyone can agree.

Syrians gather at the Bab al-Salam border gate wit FILE - Syrians gather at the Bab al-Salam border gate with Turkey, in Syria, Feb. 6, 2016. FILE - Syrians gather at the Bab al-Salam border gate with Turkey, in Syria, Feb. 6, 2016.

More than 1.2 million migrants have landed primarily on Greek and Italian shores since January 2015, and about 4,000 have drowned while trying to cross the Aegean Sea between Turkey and Greece.

Thousands more have drowned in the dangerous Mediterranean after paying human smugglers. Children have been among the victims.

Davutoglu said the refugees’ plight was not an issue of bargaining, but an issue of humanitarian values as well as European values.

VOA's Lisa Bryant contributed to this story from Paris.

In Photos: Idomeni Camp Refugees Mull Future in Europe