Turkish flags flutter nest to a huge portrait of Turkey's President and leader of the Justice and Development Party (AKP) Recep Tayyip Erdogan as he gives a speech during an AKP pre-election rally in Yenikapi Square in Istanbul on June 17, 2018. - With a week to go to crucial Turkish elections, the leader of the AKP  and his main rival of the secular Republican People's Party (CHP) are trading blows in an unexpectedly bruising fight to win control of the country. (Photo by Aris MESSINIS / AFP)        (Photo credit should read ARIS MESSINIS/AFP/Getty Images)
The Erdogan effect: How one man shaped Turkey
03:32 - Source: CNN
Istanbul, Turkey CNN  — 

The main Turkish opposition party has won the rerun of Istanbul’s mayoral election, according to Turkey’s Anadolu News Agency, in a blow to President Recep Tayyip Erdogan.

With more than 99% of the votes counted, Republican People’s Party (CHP) candidate Ekrem Imamoglu was in the lead with about 54% of the vote, state news agency Anadolu reported on Sunday.

Imamoglu said “the whole Turkey won the election, not a group or party.”

“You stood up for the democracy tradition of more than one hundred years. Thank you Istanbul,” he added.

Official results were expected early Monday, according to the Turkish election board.

Crowds of Imamoglu's supporters took to the streets of Istanbul.

Crowds of Imamoglu’s supporters took to the streets of Istanbul after the unofficial results were announced. In street parties across the city, they celebrated what they saw as a vindication after Imamoglu’s original victory in March was annulled and a revote ordered.

Binali Yıldırım, the ruling Justice and Development Party’s candidate (AKP), had about 45%, Anadolu said.

Yıldırım appeared to concede the vote shortly after the unofficial results were announced, saying: “My rival seems to be leading the election. I congratulate him. This elections showed democracy is functioning in Turkey. I wish Ekrem İmamoglu will make good services to people. For his good services we will help him.”

Erdogan congratulated Imamoglu via his official Twitter account on Sunday, but added that his party will continue to work toward its goals “without giving up democracy, rule of law, peace, wealth and stability.”

If confirmed, the result would be a major blow for Erdogan. The long-time leader was hoping for a reversal of the original vote in March, which saw his AKP lose by a slim margin. The AKP challenged the outcome of that race, claiming fraud. In a controversial ruling, the Turkish election board canceled the result and ordered a new vote.

Ekrem Imamoglu of the opposition Republican People's Party speaks to his supporters on Sunday.

The March local election marked a political earthquake for Erdogan, who has been in power since 2003. AKP lost power to CHP in the country’s three largest cities: Ankara, Istanbul and Izmir.

Istanbul was a particularly painful defeat for the president, as his own political career started there.

Istanbul, the country’s biggest city, has seen a huge economic boom during the early years of the Erdogan administration. As the economic crisis hit much of the Western world, foreign investors poured their money into Turkey, looking for high returns from the emerging economy.

The election on Sunday was a rerun of a vote from March.

But the flow of money started to dry up as the US economy got stronger again. Turkish economic growth flattened, inflation reached double digits and unemployment soared.

The struggling economy has turned some residents of Istanbul against AKP.

Following a failed military coup attempt in 2016, Erdogan and his government have clamped down on civil liberties across the country, gutted public institutions and universities, heavily restricted the media and ordered mass arrests of activists, journalists and the political opposition.