Imamoglu said his victory in the rerun election had "renewed faith in democracy and our trust in justice" after voters roundly rejected President Erdogan's candidate, Binali Yildirim.
Imamoglu won the first mayoral vote in March by a slim margin of 13,000 votes over Erdogan's chosen candidate, Binali Yildirim.
Yildirim contested the results and a new election was ordered.
With some 99 percent of ballots counted, Imamoglu was winning Sunday's rerun by more than 775,000 votes – 54 percent, with Yildirim on 45 percent, the Anadolu state news agency reported.
"It was not a single group or party, but the whole of Istanbul and Turkey that won this election," Imamoglu said in his victory speech.
"Mr President, I am ready to work in harmony with you. I convey from here my request to meet with you in the shortest time possible," he added.
Critics had accused Erdogan of refusing to give up control of Istanbul, Turkey's economic powerhouse and a crucial source of patronage for Islamic conservatives. He himself was mayor of the city a quarter of a century ago.
Conceding defeat Erdogan wrote on Twitter: "I congratulate Ekrem Imamoglu who has won the election based on preliminary results."
As the city erupted in celebrations over Imamoglu's victory, commentators noted that this was more than a municipal vote – Erdogan himself once said: "Whoever wins Istanbul wins Turkey."