Indonesian President Joko Widodo.

When he was nominated in March as a candidate for Indonesia's presidential election, polls showed Joko "Jokowi" Widodo had a 30-point lead over the man who would become his main challenger, former army general Prabowo Subianto.

But after three months of shambolic and lackluster campaigning, the wildly popular governor of Jakarta was staring at defeat.