This not only sounded nice, it actually worked nicely for a while. In its first eight years in power, the A.K.P. enacted liberal reforms and adopted liberal rhetoric. Turkey’s fundamental problem, the party said, was an overbearing state that trampled on citizens’ rights. Opposition to the state, such as the Kurdish nationalist movement, had to be understood as reactions to authoritarianism, not as plots by traitors or imperialists. Stability would come from more rights and freedoms, not fewer. As a result, the A.K.P. became the darling of Western capitals and Turkish liberals — myself among them.

But the story wasn’t over. After the A.K.P. won major victories in a constitutional referendum in 2010 and in elections in 2011 — and subdued the military — the party’s liberal rhetoric waned and its social conservatism came to the fore. Then it got worse. When the A.K.P. felt its power challenged in 2013, first by popular protests and then by a corruption investigation that many, myself included, believe was politically motivated, the party adopted the very authoritarian habits it used to oppose. Opponents turned into enemies to be crushed. The A.K.P.’s vision of democracy proved to be nothing more than the tyranny of the majority. Those who tried to stay loyal to the more liberal founding principles, including its founder Abdullah Gul, were pushed aside.

Turkey’s secularists see an Islamist conspiracy behind this: The A.K.P had hidden its “true colors” until the right time. But I think that the party’s changes involved less planning — and fewer principles. The A.K.P. adopted a liberal discourse out of mere necessity, without giving it much thought or going through a real ideological transformation. Once the party grabbed power, its members were tempted, intoxicated and corrupted by it. The cadres and classes that now rally behind Mr. Erdogan have found wealth, prestige and glory for the first time in their lives. They seem determined not to lose them — regardless of what that means for Turkish democracy.

But just because the A.K.P. failed as a model of liberal Islamism doesn’t necessarily mean that all Islamists threaten liberal democracy. Tunisia’s experience shows this. There, the Islamist Ennahda Party has proved not only popular and triumphant but also reconciliatory. Consequently, Tunisians have been able to accept an admirably liberal constitution with broad national consensus — something that looks like a distant dream for us Turks. One of their secrets, perhaps, is that Rachid Ghannouchi, a founder of Ennahda and its “intellectual leader,” is less a Machiavellian politician and more a principled scholar.

None of this means that Turkey should be pushed away from the West. Nor should anger at Mr. Erdogan and his party lead to the assumption that Turkey is always wrong or its foes are always right. Under the Erdogan government, Turkey has helped Syrian refugees more than any other country. Western countries should acknowledge this and offer support. And Turkey’s worries about Kurdish separatists are not unfounded, as proved by two recent suicide bombings in Ankara claimed by secular Kurdish militants.