Turkey's opposition has dealt President Recep Tayyip Erdogan a stinging blow by winning control of Istanbul in a rerun of its mayoral election, breaking his aura of invincibility and delivering a message from voters unhappy over his policies.

Ekrem Imamoglu of the Republican People's Party (CHP) had secured more than 54 percent of votes, with nearly all ballots opened, Turkish broadcasters said — a far wider victory margin than his narrow win three months ago.

The previous result was annulled after protests from Erdogan's Islamist-rooted AK Party, which said there had been widespread voting irregularities. The decision to redo the vote was criticized by Western allies and caused uproar among domestic opponents who said Turkey's democracy was under threat.