The United Nations and human rights groups voiced deep concerns Tuesday about the European Union's plans to send thousands of migrants back to Turkey amid fears the country cannot properly provide for them.

EU and Turkish leaders agreed overnight to the broad outlines of a deal that would essentially outsource Europe's refugee emergency. People arriving in Greece having fled conflict or poverty would be sent back to Turkey unless they apply for asylum.

For every migrant sent back, the EU would take in one Syrian refugee, thus trying to prevent the need for people to set out on dangerous sea journeys, often arranged by unscrupulous smugglers.

Turkey stands to gain billions of dollars in refugee aid, faster EU membership talks and visa-free travel for its citizens within four months.

German Chancellor Angela Merkel said that under the proposed deal, which was welcomed by all 28 EU countries, migrants who enter Europe illegally will be sent back and have to join the end of the queue to enter Europe.

But the U.N. and rights groups are not convinced that Turkey is a safe destination. More than 2.7 million refugees, many from Syria, are in Turkey. Most are housed by Turkish families or live out in the open, and few have government-funded shelters.

"I am deeply concerned about any arrangement that would involve the blanket return of anyone from one country to another without spelling out the refugee protection safeguards," U.N. High Commissioner for Refugees Filippo Grandi told EU lawmakers.

Amnesty International warned that the plan, whose details are to be worked out at a March 17 summit in Brussels, is legally flawed. Europe's attempt to have Turkey designated as a safe country is "alarmingly shortsighted and inhumane," the group said.

"Turkey has forcibly returned refugees to Syria, and many refugees in the country live in desperate conditions without adequate housing," said Iverna McGowan, head of Amnesty's European office.

"By no stretch of imagination can Turkey be considered a 'safe third country' that the EU can cozily outsource its obligations to," she said.

The medical aid group Doctors Without Borders said the deal is cynical and a sign that "European leaders have completely lost track of reality."

"Clearly, Europe is willing to do anything, including compromising essential human rights and refugee law principles, to stem the flow of refugees and migrants," said the group's humanitarian adviser Aurelie Ponthieu.

Separately, U.N. Secretary-General Ban Ki-moon said he's worried by Europe's increasingly tough asylum policies, growing anti-refugee rhetoric and attacks on migrants.

"Extreme right-wing and nationalistic political parties are inflaming the situation where we need to be seeking solutions, harmonious solutions based on shared responsibilities," Ban said on a visit to Berlin.

Speaking after meeting with Merkel, Ban said he is "deeply worried by growing anti-migrant and anti-refugee rhetoric and by violent attacks against these communities."

The U.N. chief said the EU "can do much more" to manage the refugee influx, which pales next to the efforts of Turkey, Lebanon and Jordan to take in more than 5 million people between them.

Europe has been overwhelmed by the arrival of more than 1 million people in 2015 and more than 140,000 who've entered so far this year, mostly into Greece via Turkey. In response, nations along the migrant route have built barriers and tightened border controls.

Often these unilateral moves have complicated already chaotic migrant movements, putting more pressure on European neighbors and weighing on countries along the route through the Balkans north out of Greece.

Thousands of migrants are stuck at Greece's northern border with Macedonia at a makeshift and overcrowded camp near Idomeni. Many had risked their lives crossing the Aegean Sea in rickety boats.

Heavy, overnight rain had turned much of the camp into a muddy swamp, with people trying to dry their clothes and blankets at small fires.

Slovenian Prime Minister Miro Cerar said the EU summit sent "a very clear message to all traffickers and all irregular migrants that this route no longer exists, it is closed."

He said Slovenia would soon allow passage only to those migrants with documents required by EU's Schengen-member states. He did not specify the required documents.

The issue of whether the Balkans route is actually closed was a major point of contention at the summit, with Germany and other partners arguing it was not.

___

Associated Press writers Raf Casert in Brussels, Geir Moulson in Berlin, Elena Becatoros in Idomeni, Greece, and Dusan Stojanovic in Belgrade contributed.