To understand the significance of this, it helps to know the dominant narrative of Turkish politics today. It goes something like this: Throughout its republican history, Turkey has been governed by a secular elite characterized by its impish adherence to Western imperialists.

A group of plucky conservatives kept challenging this system until, in 1994, a young Erdogan and his friend (now dismissed) won the mayoralties of Istanbul and Ankara, respectively. Amid the economic crises, weak coalition governments and civil unrest of the 1990s, Mr. Erdogan and his associates were islands of good governance. They served these great cities with distinction and earned a reputation of incorruptibility.

In 2002, their movement, now under the banner of the A.K.P., was elected into national office. Under Mr. Erdogan’s firm leadership, they grew the economy, fixed the bureaucracy and won up to half of the popular vote. Turkey was booming; the world talked about the “Turkish model” of majority-Muslim democracy. By the mid-2010s, Mr. Erdogan had defanged the coup-prone military and disenfranchised the corrupt elites of old.

The jealous opposition parties joined shadowy outside actors in plotting the downfall of Turkey’s great revival. Some of Mr. Erdogan’s friends and allies betrayed him, but “the people” did not. When the economy slowed down, or the court system got clogged up, he asked people to sacrifice for the cause of what he called “New Turkey,” a nation unshackled from Western domination and free to soar to new heights.

But the myth of New Turkey is paradoxical. It was built on doing practical things in the 1990s, like filling potholes. But to maintain the myth, Mr. Erdogan sometimes asked voters to ignore those practical things and simply to have faith in “the cause.”

On Sunday, there was a major breach in this wall of faith, especially in Istanbul, where Mr. Erdogan’s love of the people first transmuted into government service. This was probably due to a combination of growing economic problems and an increasingly competent opposition.

It is a close count in Istanbul, and the Supreme Electoral Council has asked for three days to check everything. As things stand, it seems that Mr. Imamoglu, the young and stubbornly positive candidate of the C.H.P., will get the job that started Mr. Erdogan’s “great love affair” with the people 25 years ago.