Indonesian President Joko Widodo appeared set for a second term as "quick count" results from Wednesday's election rolled in, but his challenger claimed that he had won the popular vote and urged supporters not to let his victory be snatched away.
Data from private pollsters based on counts of vote samples were in line with opinion polls that had predicted a win for Widodo, a former furniture businessman and low-key reformist.
They showed him winning the popular vote with about 54 percent, with a lead of between 7.1 and 11.6 percentage points over former general Prabowo Subianto, who was narrowly defeated when he took Widodo on in the last election five years ago.
In previous elections, the counts from reputable companies proved to be accurate.
But Prabowo, a former son-in-law of military strongman Suharto who was overthrown in 1998, told a news conference that - based on internal exit polls and "quick count" numbers - his campaign believed his share of the vote was in a 52-54 percent range.
"We have noted several incidents that have harmed the supporters of this ticket," he said, without giving detail. "The truth will win."
In 2014, Prabowo had also claimed victory on election day, before contesting the results at the Constitutional Court, which confirmed Widodo's win.
Widodo said the results indicated he had regained the presidency of the world's fourth-most-populous nation, but urged supporters to wait for the election commission to announce official results.
Kevin O'Rourke, a political analyst and author of the Indonesia-focused newsletter Reformasi Weekly, said that Widodo's re-election was now clear but his victory over 67-year-old Prabowo was not resounding.
"He failed to attain the psychological 60 percent level that had seemed within reach," O'Rourke said. "Prabowo performed better than expected, which may embolden him to run yet again in 2024, if he is sufficiently fit."
Widodo grew up in a riverside slum and was the first national leader to come from outside the political and military elite. Popularly known as Jokowi, his everyman image resonated in 2014 with voters tired of the old guard.
The eight-hour vote on Wednesday for both the presidency and legislature seats across a country that stretches more than 5,000 km (3,000 miles) from its western to eastern tips was both a Herculean logistical feat and testimony to the resilience of democracy two decades after authoritarianism was defeated.
The poll followed a campaign dominated by economic issues but was also marked by the growing influence of conservative Islam in the world's biggest Muslim-majority nation.
A senior government official close to the president said before the election that a win for Widodo with 52-55 percent of the vote would be a "sweet spot", and enough of a mandate to press on with, and even accelerate, reforms.
The official election results will not be published until May. Any disputes can be taken to the Constitutional Court where a nine-judge panel will have 14 days to rule on them.
More than 10,000 volunteers crowd-sourced results posted at polling stations in a real-time bid to thwart attempts at fraud.
However, even before the election, the opposition alleged voter-list irregularities that it said could affect millions and vowed legal or "people power" action if its concerns were ignored.
Ferdinand Hutahaen, a spokesman for the Prabowo campaign, sought to soothe concerns this could mean a violent response.
"Don't consider 'people power' as a form of violence," he told reporters. "There will be no burning, killing. We will see what kind of 'people power' and revolution society wants. We don't want conflict in this country."
Prabowo's supporters would march in central Jakarta after midday prayers on Friday, campaign officials said.
Analysts are trying to assess whether Widodo will accelerate the cautious reform agenda of his first term and open up more areas to foreign investors, or even try to free up restrictive labour laws.
This will partly hinge on his ability to get laws through a newly elected parliament and to take on nationalist forces.
Widodo campaigned on his record of deregulation and improving infrastructure, calling it a step to tackling inequality and poverty in Southeast Asia's biggest economy.
But religion has also been a factor. Conservative Muslim groups have been increasingly influential.
Widodo, a moderate Muslim from Java island, had to burnish his Islamic credentials after smear campaigns and hoax stories accused him of being anti-Islam, a communist or too close to China, all politically damaging in Indonesia. He picked Islamic cleric Ma'ruf Amin, 76, as his running mate.
Prabowo, a former special forces commander who has links to some hardline Muslim groups, and his running mate, business entrepreneur Sandiaga Uno, pledged to boost the economy by slashing taxes and cutting food prices.