Ahok, who was Jakarta's first ethnic Chinese governor and first Christian in half a century, has been popular with middle-class Jakartans for his efforts to stamp out corruption in the city administration and make the overflowing polluted capital more livable. Mr Baswedan is supported by a retired general, Mr Prabowo Subianto, who narrowly lost to Mr Widodo in a 2014 presidential vote and is expected to challenge him again.
So called "quick counts" by 10 research companies show former Cabinet minister Anies Baswedan winning between 55 and 60 percent of votes with more than 80 percent of ballots counted.
The Indonesian rupiah weakened slightly after unofficial results were announced.
In one of his speeches, Ahok addressed this issue and said voters are free to choose a candidate according to their conscience.
Opinion polls in the run-up to the vote indicated that the race was neck and neck but in the event, Baswedan appeared on course for a strong victory.
Ismail Yusanto, spokesman for one of the groups, Hizbut Tahrir Indonesia, said the election showed that Jakarta voters didn't want a non-Muslim leader.
"I'm Muslim but I don't believe that any other candidate will be better than Ahok to lead Jakarta", he said.
The election is seen by some analysts as a test of secular democracy in the world's most populous predominantly Muslim country.
The early count was done by private pollsters endorsed by election officials.
"Religion has become politicized", said Fajrina Maya, 23, a campaign volunteer.More news: Large Asteroid Makes 'Very Close Approach' April 19
If convicted, he faces a maximum five-year jail sentence, though could still govern while appeals are heard.
The election outcome will be worrying all the same for Widodo, whose ruling Indonesian Democratic Party for Struggle (PDI-P) had supported Purnama's re-election bid, but whose organizational frailties, which nearly cost him the presidency in 2014, were not up to the task.
Many voters still support Purnama due to his record leading Jakarta since 2014.
Hundreds of thousands of Muslims took to the streets late previous year to call for his sacking and to urge voters against electing a non-Muslim leader. Millions of Indonesians in the capital Jakarta are elect.
When Mike Pence stops in Jakarta on Thursday, the American Vice President will land following an election whose outcome threatens Indonesia's political stability along with the reform program of President Joko Widodo.
While Indonesia's national motto is "unity in diversity" (Bhineka Tunggal Ika) the hardline Islamic community within Indonesia (a minority within the population) does not embrace this motto, or, they only embrace it as long as the motto works in their favor.
Amid the tensions, police have warned against any mass gatherings or informal monitoring of polling stations.
That might have been expected earlier in the election campaign when a conservative Islamic coalition drew impressive 100,000-200,000 crowds to two anti-Purnama rallies in downtown Jakarta.
Purnama won the first round of elections held in February but with a small margin, which is why the second and the final round is being held.