Turkish President Recep Tayyip Erdogan has suffered a major blow after his candidate for Istanbul mayor was defeated in a repeat election.
Mr Erdogan tweeted to congratulate opposition candidate Ekrem Imamoglu, who lead with 54% in early results compared to 45% for the Turkish president's chosen candidate, Binali Yildirim.
The president wrote: "I congratulate Ekrem Imamoglu who won the election according to unofficial results.
"As before, we will walk to our goals in unity and togetherness... without compromising democracy, the rule of law, peace, prosperity and stability of our country."
İstanbul Büyükşehir Belediye Başkanlığı yenileme seçimi sonuçlarının İstanbul'umuz için hayırlara vesile olmasını diliyorum. Milli irade bugün bir kez daha tecelli etmiştir. Gayrı resmi sonuçlara göre seçimi kazanan Ekrem İmamoğlu'nu tebrik ediyorum.
— Recep Tayyip Erdoğan (@RTErdogan) June 23, 2019
Mr Imamoglu previously won a mayoral election on March 31st, but Erdogan's ruling party challenged the vote and the results were annulled after weeks of partial recounts.
The opposition candidate was stripped of the post of mayor after serving just 18 days and another election was ordered.
Concerns were raised about the voided vote both in Turkey and abroad, as many questioned the country's democracy and whether Mr Erdogan's party would ever concede defeat.
In a speech declaring his victory for the second time on Sunday, Mr Imamoglu thanked his supporters as they chanted: "Mayor again! Mayor again!"
"You have protected the reputation of democracy in Turkey with the whole world watching," he told the crowds outside the headquarters of the Republican People's Party.
He was also congratulated by Mr Yildirim, who conceded defeat on national television, saying: "I congratulate him and wish him success."
The results mean Turkey's largest city will not be governed by Erdogan's AKP party for the first time in a quarter of a century.
Turkish media has put Mr Imamoglu's lead on Sunday at about 700,000 votes - far more than the roughly 13,000 vote margin in March.
The ruling party also lost control of Turkey's capital city, Ankara, following the local elections in March.
However, the party still controls 25 of Istanbul's 39 districts and holds a majority in the municipal assembly.
Mr Imamoglu told the president he was ready to work with him to solve the city's problems, although Mr Erdogan has previously appeared unwilling to co-operate with him.