Joko Widodo was hailed as Indonesia's answer to Barack Obama.

Indonesia's President Joko Widodo was sworn in for a second term on Sunday, as helicopters flew overhead and troops kept watch in the capital Jakarta -- days after terrorists tried to assassinate his top security minister.

Foreign heads of state, lawmakers and political rivals looked on as Widodo, 58, and Vice President Ma'ruf Amin, 76, read an oath to start a five-year tenure leading the world's biggest Muslim-majority nation.

Outside parliament, red-and-white Indonesian flags dotted parts of the city, but celebrations were muted with supporters outnumbered by some 30,000 security personnel deployed amid fears of another attack.

Demonstrations were also banned on Sunday as extremist violence continues to plague Indonesia.

Several thousand supporters, many wearing T-shirts bearing the leader's image, watched the ceremony on a big screen near Jakarta's national monument.

"I was worried Islamic (hardliners) would take over the country if he lost," supporter Suprihatini, who goes by one name, told AFP.

"I'm Muslim, but I don't want that kind of movement here," the 53-year-old added.

Widely known as Jokowi, the president said his final term would be aimed at eradicating poverty and catapulting the nation of some 260 million into a developed country with one of the world's top five economies by 2045.

"I'm calling on ministers, public officials and bureaucrats to take these targets seriously," he told parliament, adding that officials not committed to his goals would be sacked.

In Jakarta, supporters carried a 200-metre (655 foot) Indonesian flag along the streets, while Jokowi fans erected a seven-metre (23 foot) tumpeng in his honour -- a towering rendition of a popular cone-shaped dish -- in the country's second-biggest city Surabaya.

'Critical times'

Jokowi, a popular, heavy metal-loving former businessman from outside the political and military elite, was hailed as Indonesia's answer to Barack Obama when he was first elected in 2014, partly on a roads-to-airports infrastructure drive.

But his leadership has been under mounting criticism after a wave of crises that threaten to cast a shadow over his final term.

Challenges facing the president range from nationwide anti-government demonstrations -- in which three students died -- and smog-belching forest fires that sparked diplomatic tensions with Indonesia's neighbours, to deadly unrest in Papua province and a slowdown in Southeast Asia's biggest economy.

It marked a stark reversal of fortune just months after Jokowi scored a thumping re-election victory against a former military general.

"This is the weakest point in Jokowi's political leadership," said Arya Fernandes, a researcher at the Jakarta-based Centre for Strategic and International Studies.

"It's a test for the president in critical times."

Protests erupted last month across the archipelago that were among the biggest student rallies since mass demonstrations toppled the Suharto dictatorship in 1998.

Jokowi's inauguration comes a little over a week after the country's chief security minister was stabbed in an attack by two members of a local extremist outfit allied to the Islamic State group.

Two suspects were arrested at the scene, while dozens of suspected terrorists have since been detained in a country-wide dragnet following the assassination attempt on Wiranto, a former general who goes by one name. The 72-year-old is recovering in hospital.

Jokowi's new term also comes amid criticism that Indonesia's two decades of democratic reforms are being eroded under the watch of a man once lauded by Time magazine as "A New Hope".

Choosing conservative cleric Amin as vice president has also thrown Indonesia's reputation for tolerant Islam into question.

Jokowi's administration appeared caught off guard in September's protests that saw thousands of students hit the streets to demonstrate against a raft of divisive reforms, including banning pre-marital sex and changes that critics said would weaken the anti-graft agency.