The disputed outcome raised the prospect of short-term uncertainty for Asia's fifth-largest economy and the world's third-biggest democracy, after unofficial counts by two survey companies showed Jakarta governor Joko Widodo, 53, secured more votes than Suharto-era general Prabowo Subianto, 62.
Both candidates in their victory speeches called on supporters to guard against attempts to manipulate the tally, while outgoing President Susilo Bambang Yudhoyono urged supporters on both sides to remain calm following the vote.
"This is the first close election in Indonesia - this is going to be a test of the system," said Andrew Thornley, Jakarta-based program director for elections at non-profit development organization The Asia Foundation. "Once ballot boxes go up the chain, there is a risk of fraud."
Before the election commission can release official results by July 22, it must tally the ballots of the forecast 75% of 190 million eligible voters who turned out. The results are hauled, sometimes by boat, horseback and on foot, from polling stations on 900 inhabited islands in the Southeast Asian archipelago to regional centres. While counting at local booths is done publicly - those figures form the basis of the quick counts - adding the results up is done in secret.
"We will do our best and be professional," Ferry Kurnia, a commissioner at the General Elections Commission, or KPU, said yesterday after the quick count figures. The commission dismissed more than 200 organizers for not following procedures, he said before the election.
Some names registered as voters in the eastern Nusa Tenggara islands were found to be dead or were children, Vinsensius Bureni, a coordinator at non-governmental organization Bengkel APPEK, said by phone from Kupang in West Timor.
"This is the time for us to guard the vote counts in the polling stations so everything can go in a clean way and smooth way," Mr Widodo, known as Jokowi, told reporters yesterday. "I ask all Indonesian people to preserve the people's will and that no-one shall try to taint the aspiration of the people."
Mr Prabowo said quick counts done by survey companies he used for guidance showed him in the lead, and he would now wait for the official results.
"Let's stay alert," he said in a televised appearance as his supporters, dressed in white, whooped and cheered. "Let's close our ranks, our strength is large, our strength is the strength of the people of Indonesia."
Indonesia's benchmark stock index and rupiah rose after some of the unofficial counts showed Mr Jokowi in front, with the rupiah hitting a seven-week high. The Jakarta Composite Index was 1.5 percent higher at 9:09am.
Indonesia's newspapers praised the election for running smoothly and being violence free. The Jakarta Post and Investor Daily called it a "People's Victory" in noting Mr Jokowi's lead, while The Jakarta Globe's headline read "A Nation Awaits."
The campaign was the most polarizing since the fall of dictator Suharto in 1998, dividing the country between those looking for a more liberal democracy and those nostalgic for a leader who projects strength. The possibility that official results will be contested raises the prospect of instability that may rattle the world's fourth-most populous nation.
"This is one of the biggest tests for Indonesia, a maturity test for the young democracy," said Wellian Wiranto, an economist at Oversea-Chinese Banking Corp. in Singapore. The potential for a court challenge "will act as a brake to the kind of positive reaction to a Jokowi win given the risk of dragging drama and also the non-negligible risk of political frustration boiling over."
Mr Jokowi had about a five percentage point lead, according to unofficial counts from two survey companies that declared him the winner. The tallies give him a buffer of about 8 million votes, based on Bloomberg calculations, for the closest result since direct presidential elections began a decade ago.
Mr Jokowi fared best in the eastern part of Indonesia such as Bali and Papua, as well as Jakarta, while Mr Prabowo led in western areas including West Sumatra and West Java, according to the quick count by Saiful Mujani & Research Consulting.
The success of any court challenge would likely depend on the margin of victory in the official results, said Susi Dwi Harjanti, an associate professor of constitutional law at Padjadjaran University in Bandung, West Java.
"If the constitutional court says the margin is too big and it will not influence the results, and from the evidence the case is weak, they will not accept the case," she said.
There are nine judges on the country's constitutional court, serving terms of five years, according to its website. The chief judge is Hamdan Zoelva, previously a lecturer and lawmaker, who replaced Akil Mochtar, who was found guilty of graft and money laundering and sentenced on June 30 to life in prison. Three judges are recommended to the president by the supreme court, three by the People's Representative Council, and three are the president's own picks.
A victory for Mr Jokowi would cap a rapid ascent for the man who in 2005, as a furniture dealer with no political experience, ran for mayor in his hometown of Solo in central Java. His middle class background and penchant for mingling with the people captured the imagination of voters nationwide, propelling him to governor of the capital in 2012.
"If he wins the presidential election it means Indonesians, half of them below the age of 29, want a leader they can associate with, not part of the elite," said Fauzi Ichsan, a finance adviser to Mr Jokowi's party. "They want a leader who seems approachable, part of them, has suffered like them. Therefore any of the so-called common people can become like him in the future."
Mr Prabowo, who is the son of a former cabinet minister and was once married to Suharto's daughter, is a product of the aristocracy that has governed Indonesia since independence from the Dutch in the 1940s. During his father-in-law's rule he ascended through the army, though after Suharto was toppled he was dismissed amid accusations of human rights violations related to the detention of pro-democracy activists.
Mr Prabowo's supporters cast him as strong and capable, an image he played off during the campaign with military-themed events, while Mr Jokowi's supporters portrayed their candidate as free from vested interests and able to deliver change. Indonesia's election pitting an established elite against a new breed of politician comes as neighbour Thailand remains under military rule after years of societal divide have threatened to spill into protracted violence.
Mr Prabowo was potentially setting himself up for "a rather embarrassing retraction," said Steve Wilford, Asia-Pacific director of Control Risks. "By almost all accounts he is behind in this poll. So it would seem that he has the intent to be disruptive."
Both candidates campaigned on populist platforms, promising to spark growth, reduce poverty, boost education, build infrastructure and help farmers. Mr Jokowi has said he'll improve regulations to attract investment and cut red tape. Mr Prabowo wants to raise more money from capital markets and tax, as well as spur economic expansion by increasing borrowing.
Whoever wins will face challenges both at home and abroad. They will need to provide jobs and education to a growing population at a time when demand for its commodities such as coal and palm oil has slowed. They will also face increasingly complicated regional relations, including territorial disputes with China that are simmering on its doorstep in the South China Sea.
"Jokowi's challenge will be meeting expectations," Mr Wilford said. "You are in a realm of very, very powerful interest groups, you're in the realm of the pressures from a legislature that will actually be by headcount more aligned with Prabowo."