Republican People's Party mayoral candidate Ekrem Imamoglu addresses supporters at an election rally in Istanbul on Saturday. (Umit Bektas/Reuters)

There’s a well-known saying in Turkish politics: “Whoever wins Istanbul, wins Turkey.”

President Recep Tayyip Erdogan’s political career validates this maxim. It began a quarter of a century ago when he became the mayor of Turkey’s largest city. That success, however, owed as much to the fragmented political landscape as the personal qualities of this ambitious young politician. In 1994, the two center-right parties shared 38 percent, while the three center-left candidates totaled 32 percent. The Islamist Erdogan thus won the prize with a mere 25 percent.

He reached out to the impoverished migrants in this megapolis of what was at the time nearly 10 million people: He was one of them, after all. Despite his religious education, he had once dreamed of becoming a professional soccer player; for much of his youth he played for a local team, later working as a janitor at a state electricity company until he was fired during the 1980 military coup.

He was promising democracy, assimilation with the West and prosperity. In the national election in 2002, the centrist parties were wiped out and Erdogan finally came to power.

Seventeen years later, however, it’s very different picture.

That ambitious young man who once wanted to play football in Istanbul settled into a palace in Ankara. All his promises forgotten, he sank into a life of luxury surrounded by bodyguards. Journalists reporting on corruption allegations involving him, his family and cabinet ministers are punished by imprisonment. Founding party members — his former colleagues — have all been pushed out.

The economy is now in the hands of his son-in-law. And once he ran out of things to promise, and the economy tanked, he turned into a total autocrat.

On Sunday, 25 years after that local election, he faces another tough test. Erdogan, knowing just how important Istanbul is from his personal experience, is focusing fiercely on making sure his party controls the city government. After naming former prime minister Binali Yildirim as his candidate for mayor of Istanbul, he left his palace to hit the campaign trail. He is using the now-cowed media as his primary instrument in a fear-based strategy: He claims that all of his enemies — the Kurdish Workers Party, the Gulenists, the atheists and the international capitalists and businesses such as George Soros and J.P. Morgan — are teaming up to topple him in order to destroy the Turkish economy and partition the country.

One of his rivals (Selahattin Demirtas) is jailed, and a similar fate threatens another (Meral Aksener). A pro-Erdogan TV station called Kemal Kilicdaroglu, the leader of the main opposition party, “a candidate for the rope.” Erdogan later condemned New Zealand’s abolition of the death penalty and demanded its reinstatement.

This aggressive campaign transformed ordinary local elections into a referendum about Erdogan himself — a matter of national “survival.”

But this ploy appears to have backfired. Some polls are predicting a serious loss for the ruling Justice and Development Party (AKP) and its nationalist allies. Having learned their lesson from the election of 1994, the opposition has joined forces: the Republican People’s Party on the left, the Iyi Party on the right.

The opposition candidate for mayor of Istanbul is a relatively unknown social democrat by the name of Ekrem Imamoglu. His preternatural calm a stark contrast to the vitriol of his rivals, this latecomer is offering a message of “peace rather than tension” — and it’s closing the gap.

Erdogan, who has always kept a close eye on the polls, now dismisses them as “unreliable” — which suggests the results on his desk do not bode well. In a desperate move, he threatened dismissal of the opposition candidates “even if they’re elected.” That backfired, too: The opposition rallied round its candidates.

And it was just at that moment when totally unexpected support came from the farthest corner of the globe. The terrorist who attacked the mosque in Christchurch, New Zealand, specifically targeted Erdogan in his manifesto. It was a priceless propaganda gift just when the president of Turkey needed it most.

Endlessly rerunning clips from the gunman’s own video at demonstrations, Erdogan styled himself as a Muslim leader holding fast against an aggressive West: “Remnants of the Crusaders cannot prevent Turkey’s rise.” The Christchurch shooter vowed to retake Constantinople and destroy every mosque — prompting Erdogan to declare that he would turn Hagia Sophia (the famous Byzantine church that is now a museum) into a mosque.

But neither tales of ogres nor an assailant in New Zealand seem capable of reversing the trend in the polls. The electorate cares more about putting food in the pot than some Australian turning up in Istanbul.

So, once again, it’s decision time for the residents of the city of 15 million. Let’s see how they choose.

Read more:

Enes Kanter: Anyone who speaks out against Erdogan is a target. That includes me.

The Post’s View: Erdogan is transforming Turkey into a totalitarian prison

Can Dundar: When it comes to defending the press, President Erdogan is the world’s biggest hypocrite

Recep Tayyip Erdogan: The New Zealand killer and the Islamic State are cut from the same cloth

The Post’s View: Trump is right to push Turkey. He’s just doing it wrong.