The Election Commission announces Joko Widodo won 55.5 percent of the vote in the April 17 election and his challenger former general Prabowo Subianto 45.5 percent.
Indonesia's President Joko Widodo has been elected for a second term, official results showed Tuesday, in a victory over a would-be strongman who aligned himself with religious hardliners.
Official counting was completed just before midnight and the Election Commission announced the formal result early Tuesday. It said Widodo won 55.5 percent of the vote in the April 17 election to 45.5 percent for his challenger, ultra-nationalist former general Prabowo Subianto.
"After we're sworn in... we will be president and vice president," Widodo told reporters in Jakarta with running mate Ma'ruf Amin at his side.
"We will be the leaders and protectors of all Indonesians," he declared as his rival repeated claims of widespread cheating.
Subianto said on Tuesday he did not accept official election because he believed there had been cheating in the poll.
He also told reporters he would "continue to make legal efforts in line with the constitution to defend the mandate of the people and the constitutional rights that were seized".
City on alert
Thousands of police and soldiers are on high alert in the capital Jakarta, anticipating protests from supporters of Subianto.
The Election Commission's headquarter in central Jakarta is barricaded with razor wire and heavily guarded.
Subianto, who also lost to Widodo in 2014, hasn't provided any credible evidence of the massive election fraud he alleges.
Votes are counted publicly and the commission posts the tabulation form from each polling station on its website, allowing for independent verification.
The formal result was almost the same as the preliminary "quick count" results drawn from a sample of polling station s on election day.
Indonesia, the world's most populous Muslim-majority nation, is an outpost of democracy in a Southeast Asian neighbourhood of authoritarian governments and is forecast to be among the world's biggest economies by 2030.
A second term for Widodo, the first Indonesian president from outside the Jakarta elite, could further cement the country's two decades of democratisation.
Campaigns of fear and democracy
Widodo's campaign highlighted his progress in poverty reduction and improving Indonesia's inadequate infrastructure with new ports, toll roads, airports and mass rapid transit.
Subianto ran a fear-based campaign, emphasising what he sees as Indonesia's weakness and the risk of exploitation by foreign powers or disintegration.
He aligned himself with hardline Muslim groups and won massive majorities in conservative provinces but was defeated by Widodo in his populous East Java and Central Java strongholds.
Subianto declared himself the winner last month and in a video released after results were announced Tuesday again refused to concede defeat but called on supporters to refrain from violence.
Under Indonesia's election law, Subianto can dispute the results at the Constitutional Court.
He and members of his campaign team have said they will mobilise "people power" for days of street protests rather than appeal to the court because they don't believe it will provide justice.
"We reject the results of the presidential election," said Azis Subekti, one of the witnesses for Subianto at the official declaration of results. "This refusal is a moral responsibility for us to not give up the fight against injustice, fraud, arbitrariness, lies, and any actions that will harm democracy."
Police this month have arrested 31 militants they say planned to set off bombs during expected street protests against the election result.
The Election Commission said Widodo won in 21 of 34 provinces and got 85.6 million votes compared with about 68.5 million for Subianto.