Just a few months ago, the election was considered firmly in favour of Joko Widodo, who rose from humble beginnings to become the governor of Jakarta with a squeaky clean political record.
But the race is now too close to call after a late surge by Prabowo Subianto, who has wooed legions of supporters with his calls for nationalism despite allegations of widespread human-rights abuses during his military career and his connection with Suharto - his former father-in-law.
When the polls open to nearly 190 million eligible voters on Wednesday, analysts say those who are undecided will determine the winner.
The two candidates are vastly different in their policies and styles. Widodo, known by his nickname Jokowi, is a soft-spoken man who likes to wear sneakers, listen to heavy metal music, wear casual plaid shirts and make impromptu visits to the slums. Seen as a man of the people who wants to advance democratic reform even though he lacks experience in national politics, he represents a break from the past as the first candidate in direct elections with no connection to Suharto-era politics.
Subianto is known for his thundering campaign speeches, a penchant for luxury cars and having trotted up to one rally on an expensive horse. He has the support of the most hardline Islamic parties and has sparked concern among foreign investors worried about protectionism and a possible return to more Suharto-era policies.
"Many Indonesian Muslims prefer Prabowo's strong and dynamic character, which can stand up in facing the foreign policies of neighbouring countries and the US" said Ikrar Nusabhakti, a political analyst from the Indonesia Institute of Science. "While other people are responding positively to Jokowi's caring and earthy traits."
Black campaigns, as smear campaigns are known here, have surfaced in both camps. But Widodo, 53, has blamed his fall in opinion polls - from a lead of more than 12 percentage points in May to just around 3.5 points now - on character assaults that accused him, among other things, of not being a follower of Islam. He has denounced the charges as lies, but says it's hard to undo the damage it caused in the world's most populous Muslim nation.
"I think these black campaigns were effective enough to convince communities,'' said Hamdi Muluk, a political analyst from the University of Indonesia. ''And that has directly ruined Widodo's image."
But he added that Subianto's past, including allegations that he kidnapped pro-democracy activists prior to Suharto's fall in 1998, have not gone unnoticed and some voters fear a return to the brutal dictator's New Order regime.
"Considering the role models and figures behind Widodo's team, I believe many new voters tend to support Jokowi," Muluk said. "A return to the New Order is not popular among youngsters or new voters. They are interested more in change."
The race is the country's third direct presidential election, and has played out with fury in the social-media crazed country of around 240 million people. There has been a frenzy of "unfriending" on Facebook pages belonging to users who support different camps.
For the first time in its 31-year history, the English-language Jakarta Post last week endorsed a presidential candidate. In choosing Widodo of the Indonesian Democratic Party of Struggle, the paper said it simply could not remain silent because the stakes were too high.
"Rarely in an election has the choice been so definitive," it said in denouncing Prabowo. "Never before has a candidate ticked all the boxes on our negative checklist. And for that we cannot do nothing."
But Subianto, 62, of the Great Indonesia Movement Party, has been gaining allies. Outgoing President Susilo Bambang Yudhoyono's ruling Democratic Party, which said it was neutral earlier in the campaign, openly endorsed Subianto just two weeks before the election.
Yudhoyono, who is constitutionally barred from seeking a third term after 10 years in office, has ordered an increased police and military presence on election day to thwart potential violence.
Subianto's vows of tough leadership and promises that "Indonesia will become an Asian tiger once again" have also gained footing with some voters fed up with Yudhoyono, who has been criticized for being ineffective and weak on some issues, including those involving neighbours Australia and Malaysia. The president's party has also been plagued by a string of recent high-profile corruption scandals.
Yudi Koesnaedi, a 19-year-old college student, said Indonesia now needs a firm and authoritative leader to solve domestic problems and to answer global challenges.
"I'll go and cast my vote for the first time for president," he said. "And I think Prabowo Subianto is the most logical person to lead this country."