Istanbul, Turkey —The opposition candidate for mayor of Istanbul celebrated a landmark win Sunday in a closely watched repeat election that ended weeks of political tension and broke President Recep Tayyip Erdogan's party's 25-year hold on Turkey's biggest city. The victory by Ekrem Imamoglu, 49, is a stunning victory for the opposition party in Turkey, which had initially won the mayoral election in March before the vote was challenged by Erdogan's governing party.

"Thank you, Istanbul," said Imamoglu, a former businessman and district mayor, 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 Imamoglu, 54% to 45%. Imamoglu increased his lead from a March mayoral election by hundreds of thousands of votes, which made any attempt by the governing party to refute his victory increasingly unlikely.

Ekrem Imamoglu, candidate of the secular opposition Republican People's Party, or CHP, waves to their supporters outside a polling station in Istanbul, Sunday, June 23, 2019. AP

Erdogan also congratulated Imamoglu in a tweet, a departure from how the longtime leader of Turkey reacted to the initial vote in March. Imamoglu narrowly won Istanbul's earlier mayor's contest on March 31, but Erdogan's conservative, Islamic-based Justice and Development Party, AKP, challenged the election for alleged voting irregularities and demanded a re-vote of the same election in May. Imamoglu spent 20 days in office before Turkey's electoral board annulled the results after weeks of partial recounts. The Istanbul municipality deleted all tweets that were posted by Imamoglu during his 20 days in office as mayor.

Get Breaking News Delivered to Your Inbox

The voided vote raised concerns domestically and abroad about the state of Turkish democracy and whether Erdogan's party would accept any electoral loss. Turkey is a NATO member that is still formally a candidate to join the European Union. Erdogan's AKP party has governed Turkey since 2002. On Sunday, Imamoglu's victory for the secular Republican People's Party marked a new course for Turkey's politics.

"You have protected the reputation of democracy in Turkey with the whole world watching," Imamoglu, his voice hoarse after weeks of campaigning, 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. Jubilant supporters chanted "Mayor again! Mayor again!" Others hung out of cars, blaring horns and waving red-and-white Turkish flags.

Supporters of Ekrem Imamoglu, the candidate of the secular opposition Republican People's Party, CHP, celebrate in central Istanbul, Sunday, June 23, 2019. AP

Erdogan campaigned for 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. Imamoglu will have to work with those officeholders to govern Istanbul and promised 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.

Addressing Erdogan in his speech, 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 more than 15 million, draws millions of tourists each year and is Turkey's commercial and cultural hub. Straddling Europe and Asia, Istanbul accounted for 31 percent of Turkey's GDP in 2017.

Turkey's President Recep Tayyip Erdogan gestures as he delivers a speech to MPs of his ruling Justice and Development Party (AKP) at the parliament in Ankara, Turkey, Tuesday, Jan. 8, 2019. AP

Ozgur Unluhisarcikli, Ankara office director of the German Marshall Fund, argued that the loss of Istanbul is likely to fuel speculation of divisions within the ruling party and among its supporters.

"It's now clear that a sizable portion of the AKP voters is seriously dissatisfied by policies of the AKP," he said. "The (opposition) was a house that was united. The AKP house looked like one that was already divided."

The loss, he argued, also has international implications. Erdogan was already at odds with Western allies over Turkey's plans to buy the Russian-made S-400 missile defense system and its challenge of EU-member Cyprus over natural gas drilling rights. On Thursday, Erdogan said he did not see "any possibility" of U.S. sanctions happening in response to the missile purchase and threatened retaliatory sanctions.