CHP candidate İmamoğlu received 53.6 percent of the vote, compared with 45.4 percent for AKP candidate Ben Ali Yildirim.
Local media reported that the ruling party candidate congratulated opposition candidate İmamoğlu and expressed the hope that the city would serve well.
The results are a blow to President Recep Tayyip Erdogan, who put pressure on the Supreme Electoral Commission to re-vote in the city, which was the electoral reservoir of the ruling party after losing its candidate.
The decision to re-election has sparked international criticism and accusations by the opposition of eroding the rule of law. Residents in a number of areas have demonstrated knocking pots in protest.
Erdogan repeated his belief that "whoever wins in Istanbul wins Turkey", which means that the loss of the city again will be embarrassing for Erdogan and may weaken what appeared until recently to be his iron fist to power, having assumed the post of mayor of Istanbul in the nineties.
The Turkish economy is in a recession, and the United States, Turkey's NATO ally, has threatened to impose sanctions if Erdogan is to buy a Russian missile defense system.
A second loss to the Justice and Development Party (AKP) could shed more light on what the Republican People's Party (CHP) candidate for mayor Akram İmamoğlu described as a waste of billions of lira in the Istanbul municipality, which has a budget of about $ 4 billion.