Official counting was completed just before midnight and the Election Commission announced the formal result early Tuesday. It said Widodo won 55.5% of the vote in the April 17 election to 45.5% for his challenger, ultra-nationalist former Gen. Prabowo Subianto.
Tens of thousands of police officers and soldiers were on high alert in Jakarta, the capital, anticipating protests from Subianto's supporters. The Election Commission's headquarters in central Jakarta were barricaded with razor wire and heavily guarded.
Declaring victory, Widodo said he and his running mate, conservative cleric Ma'ruf Amin, "will be the president and vice president of all the people in Indonesia." Indonesia, the world's most populous Muslim-majority nation, is an outpost of democracy in a Southeast Asian neighborhood 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 democratization.
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, who also lost to Widodo in 2014 and unsuccessfully contested that result, has alleged massive election fraud but hasn't provided any credible evidence.
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 stations on election day.
Subianto campaign official Sufmi Dasco Ahmad said a legal challenge to the results would be filed in the Constitutional Court within the mandatory three days. Widodo said he "appreciated" his rival is following "a process in accordance with the constitution and the law."
Subianto and members of his campaign team had previously said they would mobilize "people power" for days of street protests rather than appeal legally because they didn't believe the court would provide justice.
Subianto ran a fear-based campaign, emphasizing what he sees as Indonesia's weakness and the risk of exploitation by foreign powers or disintegration. He aligned himself with hard-line Muslim groups and won massive majorities in conservative provinces such as Aceh, which follows Shariah law, but was defeated by Widodo in the president's populous East Java and Central Java strongholds.
Repeating his tactics following the 2014 loss, Subianto declared himself the winner not long after the election. In a video released after results were announced Tuesday he again refused to concede defeat but called on supporters to refrain from violence.
Police this month have arrested 31 Islamic 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.