• Video report by ITV News Correspondent Juliet Bremner

In a blow to Turkish President Recep Tayyip Erdogan, an opposition candidate has declared victory in the race to be Istanbul mayor for a second time.

Unofficial results show former businessman and district mayor Ekrem Imamoglu took 54% of the vote, defeating former Turkish Prime Minister Binali Yildirim who gained 45%.

Not all votes have yet been counted, but the results do not look set to change.

The outcome means Turkey's largest city will not be governed by Mr Erdogan's ruling Justice and Development Party, or AKP, party or its predecessor for the first time in 25 years.

Despite the vote count not being official yet, Mr Yildirim has conceded defeat, saying he "congratulated" his opponent and "wished him success".

Binali Yildirim has conceded defeat. Credit: AP

Early returns show Mr Imamoglu to have a lead of more than 777,000 votes.

Mr Erdogan also congratulated the opposition candidate, tweeting: "I congratulate Ekrem Imamoglu, who has won according to unofficial results."

Mr Imamoglu narrowly won office as mayor of Turkey's largest city on March 31 and served for 18 days.

Turkey's electoral board annulled the results after weeks of partial recounts and the AKP challenged the vote.

Another vote was held, with Mr Imamoglu again winning on Sunday.

"Thank you, Istanbul," the 49-year-old said in a televised speech.

Turkish President Recep Tayyip Erdogan voted in the polls. Credit: AP

His supporters were jubilant after unofficial results showed he won a clear majority of the vote.

Hundreds of opposition supporters erupted in mass celebration outside the headquarters of the Republican People's Party, which backed Mr Imamoglu, chanting "Mayor again! Mayor again!"

"You have protected the reputation of democracy in Turkey with the whole world watching," Mr Imamoglu, his voice hoarse after weeks of campaigning, told supporters.

Supporters of Mr Imamoglu celebrate his success. Credit: AP

Mr Erdogan campaigned for Mr Yildirim in Istanbul, where the President started his political career as mayor in 1994.

Mr Erdogan's AKP also lost control of the capital city of Ankara in Turkey's March local elections, which were held as the country faced an economic downturn.

The voided vote in Istanbul had raised concerns domestically and abroad about the state of Turkish democracy and whether Mr Erdogan's party, which has been in control of the Turkish government since 2002, would accept any electoral loss.

Mr Imamoglu was mobbed by supporters following his win. Credit: AP

Mr Erdogan's party still controls 25 of Istanbul's 39 districts and a majority in the municipal assembly.

Mr Imamoglu will have to work with those officeholders to govern Istanbul.

Addressing Mr Erdogan in his speech, Mr Imamoglu said, "I'm ready to work with you" to solve Istanbul's problems.

The President has previously signaled an unwillingness to do so.

Istanbul, a city of 15 million, draws millions of tourists each year and is Turkey's commercial and cultural hub.

Straddling Europe and Asia, Istanbul accounted for 31% of Turkey's GDP in 2017.