ANKARA - With his two-decade rule in the balance, Turkish President Tayyip Erdogan has pulled out all the stops on the campaign trail as he battles to survive his toughest political test yet and shield his legacy from an emboldened opposition.

Erdogan, the son of a sea captain, has faced stiff political headwinds ahead of a May 14 election: he was already facing blame over an economic crisis when a devastating earthquake in February left saw his government accused of a slow response and lax enforcement of building rules that may have saved lives.

As polls show a tight race, critics have drawn parallels with the circumstances that brought his Islamist-rooted AK Party to power in 2002, in an election also shaped by high inflation and economic turmoil.

His opponents have vowed to unpick many of the changes Erdogan has made to Turkey, which he has sought to shape to his vision of a pious, conservative society and assertive regional player.

The 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.

With so much at stake in the presidential and parliamentary polls, the veteran of more than a dozen election victories has taken aim at his critics in typically combative fashion.

Accusing the opposition of seeking advantage from a catastrophe, Erdogan has made several visits to the quake zone where more than 50,000 died, vowing rapid reconstruction and to punish builders who skirted building regulations.

He has peppered the election run-up with celebrations of industrial milestones, including the launch of Turkey's first electric car and the inauguration of its first amphibious assault ship, built in Istanbul to carry Turkish-made drones.

Erdogan also flicked the switch on Turkey's first delivery of natural gas from a Black Sea reserve, promising households free supplies, and inaugurated its first nuclear power station in a ceremony attended virtually by President Vladimir Putin.

He has enjoyed extensive coverage from mainstream media while state media has paid scant attention to his main challenger, Kemal Kilicdaroglu, prompting accusations of an unfair playing field from the opposition.

His attacks against the main opposition alliance have included accusations of support from the outlawed Kurdistan Workers Party (PKK), which has been waging an insurgency since the 1980s in which more than 40,000 people have been killed.

Kilicdaroglu, who was endorsed by the pro-Kurdish Peoples' Democratic Party (HDP), has responded by defending Kurdish rights and accused Erdogan of "treating millions of Kurds as terrorists".

As he seeks to shore up his appeal among conservative voters, Erdogan has also spoken against homosexuality, describing LGBT rights as a "deviant" concept he would fight.

'BUILDING TURKEY TOGETHER'

Polls suggest voting could go to a second round and some show Erdogan trailing. This hints at the depth of a cost-of-living crisis sparked by his unorthodox economic policies.

Authorities' drive to slash interest rates in the face of soaring inflation aimed to boost economic growth, but it crashed the currency in late 2021 and worsened inflation.

Despite indications his party could return to more orthodox policies, Erdogan last month stressed that interest rates would fall as long as he was in power and that inflation would decline with them.

The economy was one of Erdogan's main assets in the first decade of his rule, when Turkey enjoyed a protracted boom with new roads, hospitals and schools and rising living standards for its 85 million people.

"If he loses, that will damage his image. But for the people who love him, they will not give up on him very easily," said Seda Demiralp, chair of the Department of International Relations at Isik University in Istanbul.

Halime Duman said high prices had put many groceries out of her reach but she remained convinced Erdogan could still fix her problems. "I swear, Erdogan can solve it with a flick of his wrist," she said at a market in central Istanbul.

HUMBLE ROOTS

The president 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 Istanbul mayor, he stepped onto the national stage as head of the AK Party (AKP), becoming prime minister in 2003.

His AKP 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 that later came 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 for a time.

Erdogan's government said the purge was justified by threats from coup supporters, as well as Islamic State and the PKK.

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.

The drones also helped Ukraine defend against Russian invasion.

The interventions won few allies, however, and faced with a struggling economy the countdown to the election, Erdogan sought rapprochement with rivals across the region.

(Additional reporting by Jonathan Spicer and Ali Kucukgocmen; Writing by Tom Perry; Editing by Jonathan Spicer and Toby Chopra)