Despite not getting the majority that would allow him to amend the Turkish constitution, Erdogan's record-breaking third election win shows his stock is still rising.
Erdogan's star is still rising - and Turkey is willing to follow
In the spring of 1999, the mayor of Istanbul, a rising young politician with Islamist leanings, was sentenced to 10 months in jail after falling foul of Turkey's powerful generals. This military elite, often referred to as "the deep state", had deposed four prime ministers since 1960, so taking on a mayor - even in a city as important as Istanbul - was routine business.
They charged him with "inciting religious hatred" for quoting a century-old poem with Islamist themes. Defiant, the mayor vowed to his supporters: "This song is not yet over!"
On Sunday, that former mayor, Recep Tayyip Erdogan, won a record-breaking third consecutive term as prime minister in a resounding victory for the party that he helped to create in 2001 - and only 12 years after his jailhouse days. It is a remarkable political comeback story, one that has been lost in much of the analysis following the victory of Mr Erdogan's party, known as the Adelat va Kalkinma Partisi (AKP), or the Justice and Development party, which received approximately 50 per cent of the vote - a historically high number in Turkey's multiparty politics.
Back in 1999, the military establishment feared what Mr Erdogan represented more than the man himself: a rising political movement that scoffed at the cosmopolitan, secular elite, finding inspiration in moderate Islamist ideas and fusing together a powerful triumvirate of Turkey's Anatolian heartland, a new merchant class independent of the military elite, and a newly urbanised working class searching for a better life amid the dislocation of big city life and rampant inflation.
Throughout the 1990s, Mr Erdogan was a leading member of the two parties that gathered this rising political movement together - the Refah Partisi (RP), or Welfare Party, and the Fazilet Partisi, or Virtue Party. Both parties leaned heavily on moderate Islamist ideas and espoused a world view that ran counter to the secular elite. Both parties performed strongly in parliamentary elections; both parties were banned by the Turkish state.
As it turned out, the "deep state" should have feared the man as well as the movement, because Mr Erdogan has proven to be a politician of unusual gifts. After Sunday's landslide AKP victory, Mr Erdogan has emerged as perhaps the most consequential elected Turkish official since the late prime minister Turgut Ozal, who died in 1993 - and may have even surpassed him.
Ozal, in many ways, paved the way for Mr Erdogan's rise. He also mistrusted the "deep state" that deposed governments at will. He also reached deep into the Anatolian heartland - his own home - for support, promoted free market economic policies, aligned with centre-right parties and spurred the rise of the "Anatolian tigers" merchants, men of religion and commerce as opposed to the traditional Istanbul-based secular business elite.
Mr Erdogan is not from the Anatolian heartland, but an Istanbul boy from the gritty district of Kasimpaca, a world removed from the cosmopolitan cafes and secular business sphere. When he entered the mayor's office in Istanbul in 1994, few could have foreseen his meteoric rise. Even the man himself might have expressed disbelief if someone told him in 1999, sitting in jail, that he would be entering his second decade as the leading political figure in Turkey.
So, what happened? Mr Erdogan and some allies formed a breakaway group of more moderate alumni of the RP and FP in the year 2001 - the AK Party. This new party entered the elections in 2002, winning the most votes (36 per cent) and forming a government. The AKP benefited from voter anger at the failures of Turkey's politics in the 1990s, an era that saw debilitating financial crises and a series of military-civilian political showdowns.
Thus, Mr Erdogan and his party faced the classic "protest vote" victory dilemma: either deliver results or face a protest vote of your own. The AKP delivered. Per capita income has tripled, exports have quadrupled and Turkey has become a darling of foreign investors. From a whopping 37 per cent rate in 2002, inflation has steadied to the 5 per cent to 8 per cent range.
In foreign policy, the Turkish state is increasingly assertive, building alliances with emerging powers from Brazil to China, and expanding its influence in the Middle East. Meanwhile, Mr Erdogan has displayed a populist touch and an assertive Turkish nationalism, while winning admirers for his often dramatic support for the Palestine cause, storming out of a Davos session with Shimon Peres and loudly condemning Israel for the killing of activists aboard a Turkish flotilla headed to Gaza.
What will he do next? Some suggested that Mr Erdogan would interpret a resounding victory as a chance to rewrite the constitution to curb the power of the "deep state." His critics alleged that a large mandate would allow him to rewire Turkish society with socially conservative legislation, threatening Ataturk's secularising project.
As it turns out the main opposition party did not fare too badly, winning a quarter of the vote, and a Kurdish nationalist party performed better than expected. Thus an attempt to change the constitution will require some political wrangling and horse-trading. This was an impressive AKP victory, but it was no rout.
But the remarkable comeback story continues, and the Erdogan era goes on, with still a few acts to play. To borrow from his own words, "this song is not yet over".
Afshin Molavi is a senior fellow at the New America Foundation, a non-partisan think tank in Washington DC