Binali Yildirim, the ruling party candidate in the controversial re-run of Istanbul's mayoral election, conceded defeat today.

Istanbul returned to the polls today in a re-run of the mayoral election that became a test of Turkish democracy as well as President Recep Tayyip Erdogan's continued popularity at a time of economic trouble.

Election authorities annulled the first vote in March after Mr Erdogan's ruling party alleged corruption.

Critics had said Mr Erdogan simply did not like the March result, after a little-known former district mayor, 49-year-old Ekrem Imamoglu, snatched victory for the opposition by just 13,000 votes.

"Today, 16 million Istanbul residents have renewed our faith in democracy and refreshed our trust in justice," Mr Imamoglu told supporters.

Initial results from the Turkish state-run Anadolu news agency showed opposition candidate Ekrem Imamoglu leading with 54% to Mr Yildirim's 45 with more than 99% of ballots counted.

"According to the result as of now my competitor Ekrem Imamoglu is leading the race. I congratulate him and wish him good luck," Mr Yildirim said.

President Erdogan also congratulated Mr Imamoglu, writing on Twitter: "I congratulate Ekrem Imamoglu who has won the election based on preliminary results."

The city of 15 million is Turkey's economic powerhouse and has been a crucial source of patronage for Islamic conservatives since Mr Erdogan himself won the mayorship a quarter-century ago.

Ekrem Imamoglu

Mr Imamoglu (above), of the secular Republican People's Party, became a household name since being stripped of his victory, depicting the rerun as "a battle for democracy".

"Today our people will make the best decision... for the sake of our democracy, for Istanbul and also for the legitimacy of all future elections," he said after voting.

The March election showed Mr Erdogan's party remains the most popular nationwide, adored by millions for overseeing dramatic growth, fiercely defending the country's interests abroad and allowing religious conservatives a seat at the table. 

But double-digit inflation and rising unemployment have dented Mr Erdogan's reputation for economic stewardship and the AKP lost control of both Istanbul and the capital Ankara.

Mr Imamoglu, a little-known district mayor at the start of the year, galvanised voters with a relentlessly positive campaign under the slogan, "Everything will be fine".

That was in stark contrast to the usual aggressive name-calling of Turkish politics and struck a chord with voters.

"Our happiness has just started. We will celebrate til morning. We have been waiting 17 years (for a win). We believed in him and he believed in us," said 29-year-old Imamoglu supporter Eda Alday, as cars honked and fans waved Turkish flags in the street.

Mr Imamoglu faced the juggernaut of President Erdogan's ruling AKP party, which has been in power in Turkey since 2002 and remains the most popular political force nationwide.

AKP candidate Yildirim, a mild-mannered Erdogan loyalist who oversaw several huge transport projects and served as prime minister, this time quickly conceded defeat.

He had already struck a conciliatory tone earlier, saying "if we have wronged, knowingly or unknowingly, one of our fellow Istanbulites or our challengers, if we have done something unjust, I ask for your forgiveness."

As the city of Istanbul erupted in spontaneous celebrations over Mr Imamogulo's victory, commentators noted that this was more than a municipal vote, Mr Erdogan himself once said: "Whoever wins Istanbul. wins Turkey."

"It's a colossal defeat for Yildirim but also Erdogan. His gamble (in calling for a replay of the election) backfired," Berk Esen, assistant professor of international relations at Ankara's Bilkent University, told AFP.

It comes as an economic slump and rising prices have dented the president's reputation for economic stewardship, with the AKP also losing the capital Ankara in March.

"The AKP elites will probably try to de-emphasise the election and act like it's no big deal," said Berk Esen.

Mr Erdogan has already played down the importance of the re-run, saying last week that the choice of mayor was "only a change in the shop window" since the AKP controls almost two-thirds of the city's districts.

But it was a bitter loss for AKP voters, with some in tears at the party headquarters on Sunday night.

"Let them rejoice while they can, they will see...," vowed retired shopkeeper Mehmet.

For many conservatives, President Erdogan remains a hero who has brought prosperity and fiercely defended the country's interests since taking over in 2003.