A pivotal deal to staunch the flow of migrants from Turkey into the EU, masterminded by Angela Merkel, German chancellor, is in doubt after Turkey’s pro-European Prime Minister Ahmet Davutoglu resigned, reported the Financial Times (FT).

As per the daily, Ahmet Davutoglu, who personally negotiated the deal with Merkel, quit on Thursday following a power struggle with President Recep Tayyip Erdogan. The premier’s departure imperils an agreement credited with sharply reducing the influx of asylum-seekers into the EU.

To keep the pact on track, however, Ankara must still meet several benchmarks, including major revisions to its antiterrorism legislation to ensure civil liberties, which Erdogan has been loath to support. EU officials are now concerned that Ankara will backtrack on reform commitments.

When Merkel set out to persuade skeptical EU countries to back the migrant deal, one of her central arguments, according to diplomats, was that it would shore up the pro-European faction in Ankara, led by Davutoglu.

Instead, the deal hastened the demise of her main Turkish ally and left the pro-Europeans seriously weakened.

According to the Financial Times, President Erdogan saw Davutoglu’s increasingly close relationship with the EU as a threat. A rift between the two men turned into a power struggle which the prime minister lost.