Turkey and the European Union have reached a controversial deal European leaders hope will stop the flow of refugees to the continent in return for political and financial concessions for Ankara.

Turkish Prime Minister Ahmet Davutoglu and EU President Donald Tusk confirmed the agreement, which will come into force on Sunday, at a press conference in Brussels after three rounds of talks.

"Refugees, migrants, asylum seekers who are arriving in Greece, on the islands or the mainland ... will find themselves subject to processing and then, in due course, they will be sent back to Turkey," Al Jazeera's Neave Barker reported from the Belgian capital.

READ MORE: The dark side of the EU-Turkey refugee deal

The accord aims to close the main route by which a million people have poured across the Aegean Sea to Greece in the last year before marching north to Germany and Sweden.

But deep doubts remain about whether it is legal or workable, a point acknowledged even by German Chancellor Angela Merkel, who has been the key driving force behind the agreement.

"I have no illusions that what we agreed today will be accompanied by further setbacks. There are big legal challenges that we must now overcome," Merkel said after the 28 EU leaders concluded the deal with Davutoglu.

Leaders of the bloc had agreed on Thursday on a common plan under which Turkey would be given financial and political concessions in return for taking back all refugees who reached Greek islands off its coast.

Under the agreement, Ankara would take back all refugees and others, including Syrians, who cross to Greece illegally across the sea. In return, the EU would take in thousands of Syrian refugees directly from Turkey and reward it with more money, early visa-free travel and faster progress in EU membership talks.

'Stop the deal'

Just as the deal was clinched, Turkey said it had intercepted hundreds of people trying to reach the Greek island of Lesbos.

"It's a historic day today because we reached a very important agreement between Turkey and the EU," Davutoglu said at the press conference.

"Today we realised that Turkey and EU have the same destiny, the same challenges and the same future."

READ MORE: We need to be smarter about helping Syrian refugees

Discussions between EU leaders on Thursday revealed considerable doubts among the Europeans themselves over whether a deal could be made either legal in international law, or workable.

Much of the debate, Merkel said, had focused on ensuring that a plan that has outraged human rights groups could ensure that those returned to Turkey, a country with a patchy and worsening record on the matter, would have rights to asylum protected.

"An agreement with Turkey cannot be a blank cheque," Belgian Prime Minister Charles Michel warned, echoing many colleagues who face complaints that Europe is selling out to anti-refugees nationalists at home by outsourcing its problems to the Turks.

Outside the summit, rights group Amnesty International placed a large screen in the middle of Brussels' European quarter proclaiming: "Don't trade refugees. Stop the deal".

A major sticking point in the negotiations was Turkey's four-decade-old dispute with EU member Cyprus, whose President Nicos Anastasiades insisted there could be no opening of new "chapters" in Turkey's EU membership talks until Ankara allows Cypriot traffic to its sea and airports - a result of a refusal to recognise the Cypriot state.

OPINION: Is refugee issue a new membership criteria?

After EU leaders told Tusk where they could give ground and where they had "red lines", Anastasiades said he was ready to veto a deal if necessary.

There is anger in Nicosia at Merkel for appearing to make Davutoglu an offer last week without having consulted Cyprus at a time when talks on reunification with the Turkish-backed north of the island are at a delicately hopeful stage.

Tusk, a former Polish prime minister, made it clear that Cypriot interests must be respected.

Within a year, more than a million people have arrived in Europe fleeing war and poverty in the Middle East and beyond.