Anies Baswedan was on 56-57 per cent in the race to lead Jakarta compared to 41-43 per cent for incumbent Basuki Tjahaja Purnama, who is fighting for his job as he stands trial for blasphemy, according to a sample of votes counted by several private pollsters.
The vote is seen as a test of whether the moderate Islam traditionally practised in the world's most populous Muslim country is under threat from hardliners, who have led mass demonstrations against Purnama.
The race was already significant as politicians see the job as a stepping stone to the presidency in 2019 polls, but the stakes were raised dramatically by a controversy sparked by claims that Purnama had insulted the Koran.
The allegations drew hundreds of thousands of conservative Muslims onto the streets of Jakarta in major protests last year, and led to Purnama - known by his nickname Ahok - being put on trial for blasphemy in a case critics see as politically motivated.
More From This Section
The former education minister, who was accused of cosying up to hardliners to win votes from disaffected Muslims during the election campaign, thanked Jakarta's voters for supporting him.
The 47-year-old also hinted that he would move to heal the divisions in the capital, if his victory is confirmed: "We celebrate diversity... We are all ready to work together again."
Over 7.2 million people were registered to vote in the polls.
Official results will not be released until early May but the private pollsters are usually accurate.
Hardline groups had pledged to station monitors at polling booths. Police blocked the plan, warning it could cause "intimidation", but groups appeared to be outside some polling centres in defiance of the ban.
However there was no sign of unrest and police said the election had run smoothly.
Despite Purnama's first-round victory, Baswedan had been seen as the favourite in the run-off because the votes from a third, Muslim, candidate who was knocked out were expected to go to him.
Purnama's troubles began in September when he lightheartedly said in a speech that his rivals were tricking people into voting against him by using a Koranic verse, which some interpret as meaning Muslims should only choose Muslim leaders.
His long-running blasphemy trial began in December, and the verdict is expected within a few weeks.
If he were to have won the vote and then be convicted of blasphemy, he would not automatically be barred from holding office and could avoid jail for a long time by appealing.