Turkish President Recep Tayyip Erdogan, center, and Prime Minister Ahmet Davutoglu at a rally this year. (Yasin Bulbul/AP)

Turkey’s prime minister resigned Thursday after a public rift with President Recep Tayyip Erdogan, throwing the country’s politics into turmoil and paving the way for Erdogan to consolidate power at a time of domestic and regional crises.

In an otherwise defiant speech, Prime Minister Ahmet Davutoglu said he would bow out of upcoming elections for leader of the ruling Justice and Development Party (AKP). The decision meant he would also step down as premier.

“I decided to step down from my post,” Davutoglu said at the televised news conference in Ankara, the capital, after a meeting with AKP’s central committee. The party, which Erdogan founded, has governed Turkey since 2002. Davutoglu has served as prime minister since 2014.

“I have never negotiated or bargained with anyone” for any of my positions, Davutoglu said, hinting at recent divisions within the party. But “I am not planning to become a candidate in the upcoming [party] elections” on May 22.

The move marks another potential step by Erdogan to weaken the country’s parliamentary system and establish a strong presidency, further cementing his authority. Erdogan has taken an increasingly hard line against perceived opponents, and the president’s relationship with Davutoglu also grew strained.

Davutoglu, a former professor and foreign minister, reportedly was less enthusiastic about the push toward a stronger executive. And the two disagreed over many issues, such as economic policy and pretrial detention for dissidents. Erdogan has prosecuted scores for the crime of “insulting the president.”

In a surprise move last week, the AKP stripped Davutoglu of his power to appoint provincial-level party officials. On Thursday, Davutoglu cited the blow as a key reason for his resignation, saying it was “not behavior I would expect from fellow colleagues.”

“Having mandated [Davutoglu’s] resignation . . . Erdogan is now head of state, but also de-
facto head of government and head of the AKP,” said Soner Cagaptay, director of the Turkish Research Program at the Washington Institute for Near East Policy.

Davutoglu was seen as a largely compliant AKP party chief and prime minister, but “that does not seem to have satisfied Erdogan’s urge to consolidate political power in his hands,” Cagaptay said.

In addition to the latest political turmoil, Turkey faces numerous and overlapping crises, including a raging Kurdish insurgency, attacks from Islamic State militants and negotiations with the European Union over how to handle migration flows over the Aegean Sea. Turkey is a key U.S. ally in the war against the Islamic State.

Davutoglu led the discussions with E.U. leaders to secure a deal under which migrants would be returned to Turkey in exchange for aid and visa-free travel for Turks in Europe. Turkey is now hosting nearly 2 million refugees, most of them from Syria.

“It’s a bit too early to define if it will have implications and, in
that case, of what kind,” E.U. ­foreign-policy chief Federica Mogherini, on a visit to Kosovo, said of Davutoglu’s resignation, the Reuters news agency reported.

The Obama administration, too, saw Davutoglu as more of a collaborative realist than the prickly Erdogan.

Davutoglu said Thursday that he will remain loyal to Erdogan and stay in the AKP as a deputy. “You will not hear one negative word from me about our president,” Davutoglu said, warning against “speculation” over deepening rifts.

But others saw the resignation Thursday as an ominous sign of the direction of Turkish politics.

“Never before in this system has one person amassed so much power in his hands as Erdogan has,” Cagaptay said. “The risk that looms for Turkey here is the hollowing out of all institutions.”

Erdogan’s consolidation of power will “render the country so brittle politically that when Erdogan leaves office one day, there will be nearly no institutions left standing to keep the country together,” he said.

Karen DeYoung in Washington contributed to this report.