More than 190 million voters were asked to choose between an incumbent president lauded for his infrastructure projects and a fiery nationalist with links to a brutal dictatorship.
The vote officially ended at 1:00 pm (0600 GMT) in Sumatra, although some of the 800,000 polling stations across the volcano-dotted nation remained open late due to delays and long queues.
A series of so-called “quick counts” are expected to give a reliable indication of the presidential winner later Wednesday. Official results are not expected until May.
Earlier, the call to prayer had rang out as voting began at first light in restive Papua province in the east.
Almost 90 percent of the population of the 4,800 kilometre-long (3,000 mile) country are Muslim.
The campaign was punctuated by bitter mudslinging and a slew of fake news online — much directed at the presidential contenders.
Leading in pre-vote polls, President Joko Widodo, 57, has pointed to his ambitious drive to build much-needed roads, airports and other infrastructure across Southeast Asia’s largest economy.
But Widodo, a political outsider with an everyman personality when he swept to victory in 2014, has seen his rights record criticised owing to an uptick in discriminatory attacks on religious and other minorities, including a small LGBT community, as Islamic hardliners become more vocal in public life.
His choice of conservative cleric Ma’ruf Amin as his running mate has also raised fears about the future of Indonesia’s reputation for moderate Islam.
Widodo — a practising Muslim who has battled doubts about his piety — jetted to Mecca, the birthplace of Islam, for a brief, pre-election pilgrimage Sunday.
“There’s clearly less enthusiasm for Widodo now,” said Kevin O’Rourke, an Indonesia-based political risk analyst.
“His popularity is still up there … but he is not the inspiring figure that he was five years ago.”
Raised in a bamboo shack in a riverside slum, the soft-spoken Widodo stands in stark contrast to rival Prabowo Subianto, 67, a strongman who has courted Islamic hardliners and promised a boost to military and defence spending.
Echoing US President Donald Trump, Subianto has also vowed to put “Indonesia first” by reviewing billions of dollars in Chinese investment.
Subianto’s long-held presidential ambitions have been dogged by a chequered past and strong ties to the Suharto dictatorship, which collapsed two decades ago and opened the door for what is now the world’s third-biggest democracy.
He ordered the abduction of democracy activists as the authoritarian regime collapsed in 1998, and was accused of committing atrocities in East Timor.
Subianto — who has moved to soften his image with an Instagram account featuring his cat Bobby — insisted he was poised to pull off an upset victory, alongside running mate Sandiaga Uno, a 49-year-old wealthy financier.
“I’m very confident,” he told throngs of reporters in vote-rich West Java after casting his ballot.
He narrowly lost to Widodo in the 2014 polls.
A record 245,000 candidates ran for public office, from the presidency and parliamentary seats to local positions — the first time all were held on the same day.
Voters punched holes in ballots — to make clear their candidate choice — and then dipped a finger in Muslim-approved halal ink, to prevent double-voting in a graft-riddled country where ballot-buying is rife.
In Palu, which was devastated by a quake-tsunami six months ago, one woman who lost her 10-year-old daughter and her home in the disaster voiced hope that the poll could help bring some relief.
“Hopefully the president or the new legislative candidate will help people like us still living in evacuation shelters,” said Laila, who like many Indonesians goes by one name.
“All this time we’ve been living on handouts from volunteers.”
Thousands of survivors are still living in makeshift tents in the affected region of the island of Sulawesi.
‘Path of our nation’
About two million military and civil protection force members were deployed to ensure the vote went smoothly, including in mountainous Papua where rebels have been fighting for decades to split from Indonesia.
Papua election officials dressed in traditional headgear and grass skirts, as others strapped on superhero costumes to entertain voters in other parts of the country.
“I’m very happy I can still cast my vote at this old age,” 79-year-old Suparni told AFP at a polling station in Papua’s Merauke city.
“But it’s very confusing because there’s so many ballot sheets.”
The country of more than 260 million people is home to hundreds of ethnic groups and languages.
“This only happens once in five years, so we have to exercise our (voting) rights,” I Gusti Ketut Sudarsa, 65, said from holiday hotspot Bali.
“This will determine the path of our nation.”