Turkish president Recep Tayyip Erdogan has beaten back his rivals at one of his most vulnerable movements and regained his old aura of invincibility ahead of next Sunday's historic runoff election.
The ultimate political survivor, Erdogan, 69, has overcome jail and a bloody 2016 coup attempt to emerge as Turkey's most important leader since Mustafa Kemal Ataturk, the revered founder of the post-Ottoman republic.
An unprecedented opposition coalition, galvanised by a biting economic crisis and fury over a calamitous February earthquake, represented his latest challenge in last Sunday's general election.
But while coming closer to defeat than ever, Erdogan beat the odds yet again, looking increasingly likely to extend his two-decade rule for one last time until 2028.
A transformative and divisive figure, Erdogan is revered for unshackling religious restrictions in the officially secular but mostly Muslim state, overseeing ambitious infrastructure projects and turning Turkey into a geopolitical force.
Detractors accuse him of slipping into authoritarianism reminiscent of the Ottoman sultans, shaking Turkey's democratic foundations and impoverishing millions through misguided beliefs that contradict conventional economics.
Next Sunday's runoff is turning into a referendum on his rule, with its result likely to leave the sharply polarised nation of 85 million deeply divided.
Rewriting the rules
Known to his inner circle as "beyefendi" (sir) and to admirers as "reis" (the chief), Erdogan prides himself on being able to woo doubters through tireless campaigning.
This passion has helped him and his party win more than a dozen local and national elections, allowing Erdogan to claim a people's mandate for his foreign military adventures and domestic clampdowns on dissent.
Erdogan risked his political domination on a 2017 referendum over abolishing the office of prime minister and handing greater powers to the president.
Erdogan eked out a narrow win, enfeebling parliament and enabling him to effectively rule by decree. It also gave him the constitutional loophole needed to run for two more terms in office -- an outcome acquiring the air of inevitability.
Power and protests
Born in a working-class harbour district of Istanbul, Erdogan made his name in nascent Islamic movements that were challenging secular domination, becoming the city's mayor in 1994.
His term in office was cut short when he was convicted and jailed for four months for inciting religious hatred when he recited a fiery poem that compared mosques to army barracks and called minarets "our bayonets".
Among supporters, this only seemed to magnify his appeal.
Founding the AKP after an earlier Islamic party was banned, Erdogan spearheaded its 2002 landslide election victory and became premier less than six months later.
Erdogan's signature early achievements included a series of reforms that gladdened the European Union, including abolishing the death penalty and beginning a peace process with Kurdish militants.
Mass protests in 2013 over plans to turn an Istanbul park into a shopping mall marked the start of a more divisive era that included corruption allegations levelled against his inner circle.
Turkey's bid to join the EU faltered and peace talks with the Kurds imploded in 2015, when a Kurdish opposition party helped to wrest control of parliament from Erdogan for the first time.
Turkish military operations against Kurdish forces in Syria and Iraq soon followed, creating new tensions with the West.
Abandoned by allies
In its early days the AKP, lacking allies and experience, forged an alliance with Islamic preacher Fethullah Gulen, who moved to permanent US exile in 1999 but retained strong influence in Turkish society and government.
Erdogan blamed Gulen for masterminding a bloody coup bid in July 2016, by a renegade army faction -- charges he denies.
The president, on holiday in the Aegean, appeared on the FaceTime app on live TV to urge supporters out onto the streets.
It became the defining moment of his subsequent rule.
Erdogan fought back with sweeping purges that led to 80,000 arrests, brought most media under government influence and created a sense of looming peril among those opposed to his rule.
Washington and the EU's hesitation to openly support Erdogan in the first hours of the coup bid eroded his trust in the West and created diplomatic frictions that linger to this day.
Unorthodox economic policies, including lowering interest rates to fight soaring inflation that officially reached 85 per cent in 2022, hurt many ordinary Turks as the lira slumped and bills spiked.
Opponents accused him of turning a blind eye to corruption and lax building standards that allowed entire cities to crumble in this year's earthquake.
Despite the widespread loss and anger, Erdogan's popularity held up in parts of southeastern Turkey laid to waste by the disaster -- a testament to a loyal bedrock of support built up over two decades.