By Orhan Coskun and Daren Butler
ANKARA (Reuters) - Tayyip Erdogan rose to power 20 years ago as Turkey emerged from the twin blows of rampant inflation and a deadly earthquake, promising a new era of sound government after the coalition of the time was accused of mismanaging both crises.
As he seeks to extend his rule into a third decade, modern Turkey's longest serving leader is blamed by opponents for fuelling runaway inflation once again, and letting constructors flout earthquake regulations which could have saved lives.
Elections due in June - if they can be held in southern Turkey's earthquake zone where millions are homeless - are shaping up to be President Erdogan's toughest test to date at the ballot box.
His Islamist-rooted AK Party came to power in 2002 amid a financial crisis and following the collapse of a coalition government facing strong criticism over its handling of the response to a devastating 1999 earthquake.
Since the latest quake, the 68-year-old veteran of more than a dozen election victories has toured shattered cities, promising rapid reconstruction and punishment for constructors who skirted rules aimed at making buildings safe.
But that may not be enough to convince angry survivors whose homes crumpled into dust in the 7.8 magnitude quake which killed tens of thousands of people, and who said emergency rescue teams were too slow to deploy.
The leader of the main opposition Republican People's Party Kemal Kilicdaroglu, Erdogan's possible rival in the presidential vote, blamed the scale of the damage on "systematic profiteering politics" during Erdogan's two decades in power.
"If there is anyone responsible for this process, it is Erdogan. It is this ruling party that has not prepared the country for an earthquake for 20 years," he said.
Officials have said Erdogan, who turns 69 on Sunday, considered delaying the elections but now favours going ahead, confident he can rally Turkish voters around a slogan for his post-earthquake mission: "We're building Turkey together".
"Erdogan was really pained, even shaken by the earthquake. But by no means did he give up and there is no despair," one source close to him said, adding that he has shown flashes of anger when he thought people were not delivering.
The fiery campaigner has also appeared weary at times.
"His work got heavier - he was already busy," the source said. "When the visits to the earthquake sites are included ... he may seem tired, which is normal."
SURVIVED ATTEMPTED COUP
At stake in the presidential and parliamentary elections is the direction of a country which Erdogan has increasingly shaped to his vision of a pious, conservative society and assertive regional player.
Opponents have vowed to revoke the powerful executive presidency he created, returning Turkey to parliamentary democracy and restoring independence to a central bank which implemented his call for low interest rates - driving economic growth but crashing the lira and firing up inflation.
Such high stakes are nothing new for a leader who once served a prison sentence - for reciting a religious poem - and survived an attempted military coup in 2016 when rogue soldiers attacked parliament and killed 250 people.
The son of a poor sea captain, he rose from humble roots in a poor district of Istanbul where he attended Islamic vocational school, entering politics as a local party youth branch leader.
After serving as mayor of Istanbul, he stepped onto the national stage as head of the AK Party, which triumphed in 2002 national elections. He became prime minister the following year, in March 2003.
At the height of his success, Turkey enjoyed a protracted economic boom, with new roads, hospitals and schools and rising living standards for its 80 million people.
His AK Party tamed Turkey's military, which had toppled four governments since 1960, and in 2005 began talks to secure a decades-long ambition to join the European Union - a process which has now come to a grinding halt.
Western allies initially saw Erdogan's Turkey as a vibrant mix of Islam and democracy which could be a model for Middle East states struggling to shake off autocracy and stagnation.
But his drive to wield greater control polarised the country and alarmed international partners. Fervent supporters saw it as just reward for a leader who put Islamist teachings back at the core of public life and championed the pious working classes.
Opponents portrayed it as a lurch into authoritarianism by a leader addicted to power.
After the coup attempt authorities launched a crackdown, jailing more than 77,000 people pending trial and dismissing or suspending 150,000 from state jobs. Media rights groups say Turkey became the world's biggest jailer of journalists.
Erdogan's government said the purge was justified by threats from coup supporters, as well as Islamic State and Kurdistan Workers Party (PKK) militants.
At home, a sprawling new presidential palace complex on the edge of Ankara became a striking sign of his new powers, while abroad Turkey became increasingly assertive, intervening in Syria, Iraq and Libya - often deploying Turkish-made military drones with decisive force.
While they forged an indispensable role for Turkey, the interventions won few allies. Faced with a struggling economy, a weak currency and a countdown to this year's election, Erdogan sought rapprochement with rivals across the region.
The move paid off in part, with investment pledges from former rival the United Arab Emirates and warmer ties with Saudi Arabia boosting Turkey's economic prospects in the crunch election year - until the Feb. 6 earthquake struck and upended Erdogan's plans.
Now he must convince voters he is the leader to rebuild Turkey from the rubble after this month's earthquake.
"The size of the calamity is so big that the electoral cycle will inevitably be affected by this tragedy. That will be, in all likelihood, to the detriment of the ruling AK Party and President Erdogan," said Sinan Ulgen, director of the Istanbul-based Centre for Economic and Foreign Policy Studies.
(Additional reporting by Humeyra Pamuk in Istanbul; Writing by Dominic Evans; Editing by William Maclean)