The people of Istanbul are flaming mad, and with good reason: On Monday, the country’s national election board canceled the results of the March 31 mayoral election and ordered a do-over.

Why? Because President Recep Tayyip Erdogan and his ruling Justice and Development Party, or AKP, threw a fit and challenged the victory of Ekrem Imamoglu, a member of the opposition Republican People’s Party, or CHP, alleging fraud.

Imamoglu had already taken office, but a new election will take place next month, and Istanbul’s governor will designate a temporary mayor in the meanwhile.

The move dealt a fresh blow to the country’s already battered democratic system.

“Fraud and corruption are evident here,” Erdogan said in a speech on Saturday. “Let’s return to the ballot boxes.”

But of course he only had in mind those ballot boxes that the AKP didn’t capture the first time around. Overall, his Islamist party won in 40 of Turkey’s 81 provinces.

As CHP Deputy Chairman Onursal Adiguzel tweeted: “It is legal to run against the AKP, but illegal to win against them. This is a plain dictatorship. This system that overrules the will of the people and disregards the law is neither democratic nor legitimate.”

It’s not hard, however, to see why Erdogan wants to go again and try to “win” back Istanbul: It’s Turkey’s largest city and commercial nerve center, with 16 million people, and it’s the place that gave Erdogan his political start; he was mayor from 1994 to 1998.

In many ways, modern Istanbul is his baby, and he can legitimately claim credit for having transformed the city for the better during his tenure in city hall. His modernization and anti-graft successes became his springboard to national power.

But this spring, the people of Istanbul, the ones who catapulted him to nearly two decades at the top, sent him a warning with their votes. The message was that they’re dissatisfied with the way he’s running the country.

He’s become too authoritarian. Turkey is the world’s top jailer of journalists. Erdogan has purged the military, the judiciary, the education system and many other institutions, supposedly to root out “terrorists,” but really to silence the opposition.

He has also strengthened the presidency under the constitution, while the cultural changes under the AKP have left many secular and liberal Turks wondering whether they still belong. The economy, which Erdogan could boast about in the past, is now in the crapper. And Turkey is flooded with Syrian refugees.

The people have had enough.

“In soccer terms,” a former senior AKP official told me here last week, the March municipal election “was a yellow card” from the people to the party.

But it appears the AKP has resolved not to listen to the people — or foreign investors. The party’s decision to force a redo in Istanbul sent the Turkish lira tumbling, dropping more than 3 percent against the dollar.

The people sent him another warning on Monday, when spontaneous protests broke out in Istanbul, with dissidents banging pots and pans to oppose the redo.

Redoing the elections in Turkey doesn’t just set a bad precedent — it’s a watershed moment for the country, the AKP official told me.

His point was a simple one: If Turkey can keep the elections results and tell Erdogan “no,” then the country’s democratic system can remain intact, if battered (Turkey has had free and fair elections since 1950). But if the elections are repeated, it shows that Erdogan is now brazen enough to openly manipulate the system, much like the Islamists in next-door Iran.

The future of Turkey’s democracy, he told me, hangs on this. If past is precedent, Erdogan is unlikely to shift course or relinquish power, even if it means moving Turkey decisively into the camp of unfree nations.