The opposition candidate for mayor of Istanbul is celebrating a landmark win.

The closely-watched repeat election has ended weeks of political tension and broke President Recep Tayyip Erdogan’s party’s 25-year hold on Turkey’s biggest city.

“Thank you, Istanbul,” former businessman and district mayor Ekrem Imamoglu, 49, said in a televised speech after unofficial results showed he won a clear majority of the vote.

The governing party’s candidate, former Turkish prime minister Binali Yildirim, conceded moments after returns showed him trailing well behind Mr Imamoglu, 54% to 45%. Mr Imamoglu increased his lead from a March mayoral election by hundreds of thousands of votes.

Turkey Istanbul Election
Binali Yildirim conceded defeat (Emrah Gurel/AP)

Mr Erdogan also congratulated Mr Imamoglu in a tweet.

Mr Imamoglu narrowly won Istanbul’s earlier mayor’s contest on March 31, but Mr Erdogan’s Justice and Development Party, AKP, challenged the election for alleged voting irregularities. He spent 18 days in office before Turkey’s electoral board annulled the results after weeks of partial recounts.

The voided vote raised concerns domestically and abroad about the state of Turkish democracy and whether Mr Erdogan’s party would accept any electoral loss. AKP has governed Turkey since 2002.

“You have protected the reputation of democracy in Turkey with the whole world watching,” Mr Imamoglu told supporters.

Following his second victory, tens of thousands of people erupted in mass celebration across Istanbul, including outside the offices of the Republican People’s Party, which backed Mr Imamoglu.

Mr Erdogan campaigned for Mr Yildirim in Istanbul, where the president started his political career as mayor in 1994. The ruling 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 and promised on Sunday to work with his political opponents.

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, battled high inflation and two credit rating downgrades in the past year.