President Recep Tayyip Erdogan on Friday, a day after Prime Minister Ahmet Davutoglu was forced from office in what was widely seen as a move to tighten the president’s hold on power.CreditTurkish President Press Office, via European Pressphoto Agency

BERLIN — The increasingly authoritarian tilt of President Recep Tayyip Erdogan of Turkey and the ouster of his prime minister this week have European leaders newly questioning their reliance on him and the viability of an already divisive deal struck this spring that has largely halted the flow of migrants to Europe.

The widening gulf in democratic values — combined with Mr. Erdogan’s deepening intransigence — has now run up against provisions in the deal that would allow Turks visa-free travel to Europe. All this is threatening even to undo the deal.

The gap between the sides and the growing pressure on the accord became clear this week when the European Commission called on Turkey to narrow its application of antiterrorism laws and bring them in line with European Union standards — one of more than 70 conditions it has set for visa-free travel.

Turkey has very broad terrorism laws, which the Europeans fear are being used by Mr. Erdogan to crack down on his opponents. In fact, Mr. Erdogan recently said the government should widen the definition of terrorist to include journalists and academics who are deemed by the authorities to have provided support for terrorists.

But on Friday, Mr. Erdogan proclaimed with typical defiance that Turkey “will not change its antiterror law for the sake of a visa deal” that would allow the 75 million Turks easier access to Europe for three months at a time.

“We will go our way,” Mr. Erdogan said. “You go yours.”

The episode was a fresh reminder of the political costs of holding together a deal that has helped the European Union to avoid a replay of the chaotic tide of migrants that nearly collapsed its system of open borders last year.

Video

A look at how Turkey has taken an increasingly authoritative turn under the rule of President Recep Tayyip Erdogan.Published OnMay 5, 2016CreditImage by Turkish Presidential Press Office/European Pressphoto Agency

In return, however, Turkey has been promised up to 6 billion euros over three years to meet the costs of sheltering refugees from Syria and Iraq, as well as the possibility of the visa-free travel arrangement and fresh consideration of talks to enter the European Union.

But the continuing viability of the deal was called into question this week with the ouster of the Turkish official who has been most closely associated with it: Prime Minister Ahmet Davutoglu. He was pushed out on Thursday by Mr. Erdogan, in what was widely interpreted as a move by the president to tighten his hold on power.

Two weeks ago, Mr. Davutoglu was the only Turkish leader who accompanied European Union officials as they visited Gaziantep, on the Turkish-Syrian border, to see how the deal was working.

“It is clear that Davutoglu was the decisive man for the deal,” said Sylke Tempel, editor in chief of Internationale Politik, published by the German Council of Foreign Affairs.

Echoing that thought, the conservative Frankfurter Allgemeine Zeitung noted Friday that “this means that the success of the deal will now be even more vulnerable to Erdogan’s whims.” European leaders should be “on red alert for rocky relations with Ankara in the future,” it said.

Carl Bildt, the former Swedish foreign minister, appeared to be pessimistic about the future of the migration pact now that Mr. Davutoglu has resigned.

No European leader has a greater stake in making the deal work than Chancellor Angela Merkel, who took the lead in negotiating it with Mr. Davutoglu.

On a visit to Italy, the chancellor noted cautiously on Friday that “we have made good progress with the deal with Turkey. The European Union — at least Germany and Italy — is ready and stands by its commitments. We hope of course that that is mutual.”

Whether Europe and Turkey can continue to work closely together may now rest on whether Mr. Davutoglu’s replacement also embraces a vision of Turkey with one foot in Europe or Mr. Erdogan’s authoritarian bent, said Volker Perthes, a Middle East expert and director of the government-funded German Institute for International and Security Affairs.

“For now, I don’t think the costs are actually higher for Merkel” than for other European leaders, Mr. Perthes said, although “she is more personally involved in a deal which pro forma is between the E.U. and Turkey, not the member states.”

Under the deal, Turkey has already begun taking back refugees who had made their way to Greece, and the flow of migrants has virtually stopped.

The aim of robbing smugglers of business and preventing refugees risking their lives across the Aegean has thus been achieved, noted Ms. Tempel of the German Council on Foreign Relations.

But the other aspect of the deal — influencing Turkey’s internal development through conditions for travel and eventual European Union membership — is much more fragile, Ms. Tempel suggested.

If anything, it is Mr. Erdogan who has used the deal to extend his influence. That became clear for Ms. Merkel after a German satirist lampooned the Turkish leader in a crude poem that prompted Mr. Erdogan to sue under a 19th century law on offending foreign leaders.

Amid suggestions that she was effectively championing censorship, the law forced Ms. Merkel to allow the suit to go forward. She also acknowledged that she had made a mistake in initially passing judgment on the poem, agreeing with Mr. Davutoglu that it was deeply offensive.

With Mr. Davutoglu now leaving office, Ms. Merkel and the rest of Europe are left hoping for a replacement they can do business with.

Mr. Erdogan’s tough talk on Friday is probably less worrying than the fact “that we are losing one of Erdogan’s team who had a very strong interest in linking Turkey to Europe,” Mr. Perthes said. “I think he really wanted to do the deal with the Europeans, achieving this collaboration would have been a big victory for him, also as a person.”

In Turkey, some analysts said they believed Mr. Davutoglu had to go because he was cutting an increasingly independent and popular figure.

Aykut Erdemir, a former opposition lawmaker and senior fellow at the Foundation for Defense of Democracies, said, “Erdogan feared that Davutoglu could use his international profile as leverage against Erdogan to carve an autonomous sphere of action domestically.” He added, “Such a power-sharing arrangement is not something that Erdogan can tolerate.”

Mr. Perthes, the German analyst, noted that Mr. Erdogan often surprises, and not always negatively. He expressed hope that a new prime minister might be appointed with a mandate to finish the visa and other deals with Europe.

But Manfred Weber, a German lawmaker of Ms. Merkel’s conservative bloc who leads the center-right European People’s Party at the European Parliament, voiced wariness about granting visa-free travel to Turkey unless it also makes concessions.

“The resignation of the Turkish prime minister is not a good signal,” Mr. Weber said by email. The European Parliament would only hold a vote on visa waivers “if all criteria are met.”

One of the five conditions Ankara must still meet is to revise laws and practices to balance the fight against terrorism with respect for human rights.

Cem Ozdemir, a leader of Germany’s Greens and among the country’s best-known politicians of Turkish descent, said Mr. Davutoglu’s departure “underscores how much Erdogan is trying to change Turkey into a one-man state.”

It showed, he said, that Mr. Erdogan is the only negotiating partner who matters and “that you can only bet moderately on the reliability of Ankara.”

Ms. Merkel, he added, had long evinced little interest in Turkey and opposed its bid to join the European Union.

Now, he said, “it is not without irony that when Turkey is going completely in the wrong direction, she is the one opening the gates” to Europe. Ms. Merkel’s lack of Turkish allies outside the government, Mr. Ozdemir said, “is coming back to bite her.”

Alison Smale reported from Berlin, and James Kanter from Brussels. Ceylan Yeginsu contributed reporting from Istanbul.

A version of this article appears in print on , on Page A8 of the New York edition with the headline: Tensions Threaten E.U. Deal With Turkey. Order Reprints | Today’s Paper | Subscribe