Five years ago, Turkey was a beacon of hope for the troubled Middle East—not only one of the world’s fastest-growing economies but also the biggest success story in the Muslim world. Edging toward membership in the European Union and attracting waves of foreign investment, Turkey had a newfound swagger. Western and Arab leaders were hailing its ruling Justice and Development Party, or AKP, and its leader, Recep Tayyip Erdogan, for fusing Islamism and democracy inside a secular constitution.

But after more than a decade of...