Incumbent Indonesian President Joko Widodo, left, and his running mate Ma'ruf Amin wave to reporters, in Jakarta, Indonesia, Thursday, June 27, 2019. Indonesia's top court has rejected a challenge to election results that alleged massive and systematic fraud, paving the way for Joko Widodo's second term as president. (AP Photo/Achmad Ibrahim)

JAKARTA, Indonesia (AP) — Indonesia's top court Thursday rejected a losing presidential candidate's allegations of massive and systematic election fraud, sealing a second term for Joko Widodo, who in fending off the rising power of Islamists has drifted toward authoritarian tactics.

The Constitutional Court, which took a marathon nine hours to publicly read its reasoning on the case, said the legal team of the losing candidate, former Gen. Prabowo Subianto, had failed to prove allegations that included millions of fake voters and biased state institutions. The court's ruling is final.

Thousands of police and soldiers were deployed to boost security in Jakarta as authorities strove to avoid a repeat of deadly riots last month. Pro-Subianto protesters who had gathered near the court melted away around dusk as the broadcast of proceedings on a TV screen outside indicated their candidate's case was unsuccessful.

The official election results released last month showed Widodo won 55.5% of the vote but also revealed a polarized electorate. Subianto, who allied himself with groups that want Islamic rather than secular law to prevail in the world's largest Muslim-majority nation, won big victories in conservative provinces.

The legal challenge's failure was widely expected after documents filed with the court showed that much of the evidence for the alleged fraud in the April 17 election was printouts of tangentially related news articles from online sites of varying quality.

The evidence purporting to show police bias in favor of Widodo included allegations from an anonymous Twitter account. The hearings were broadcast on national TV and showed the testimony of some witnesses disintegrating under questioning from the panel of judges.

Widodo, the first Indonesian president from outside the Jakarta elite, said Indonesians should reunite after a divisive election campaign.

"In the election our political choices are different but the elected president and vice president are the president and vice president for all children of the nation, for all Indonesians," he said.

HIs administration, however, has increasingly flirted with authoritarianism, using a draconian presidential decree to ban an Islamic group that promoted Indonesia becoming a caliphate and allowing authorities to arrest opponents under an easily abused hate speech law.

The legal challenge appeared to be partly an attempt to strengthen the hand of Subianto's party, Gerindra, which has been negotiating with Widodo's governing coalition for Cabinet positions.

Minutes after the ruling, Subianto said he had "respect" for it, reducing the risk of more violent protests but also raising the possibility of his party joining Widodo's government and leaving the world's third-largest democracy without a significant parliamentary opposition.

"The ruling is very disappointing for us and our supporters, but we have committed to obey the constitution and we respect the Constitutional Court's decision," he said.

Subianto, linked to human rights abuses during the authoritarian rule of Suharto, also unsuccessfully challenged his presidential election loss to Widodo in 2014 and has now made four unsuccessful bids for the presidency.

Nine people died in what police said were orchestrated riots in Jakarta after the official results were released May 21. Amnesty International has said police used disproportionate force against protesters that resulted in unlawful killings and other human rights violations.

Incumbent Indonesian President Joko Widodo waves at reporters in Jakarta, Indonesia, Thursday, June 27, 2019. Indonesia's top court has rejected a challenge to election results that alleged massive and systematic fraud, paving the way for Joko Widodo's second term as president. (AP Photo/Achmad Ibrahim)
Losing presidential candidate Prabowo Subianto, left, shakes hands with his running mate Sandiaga Uno during a press conference in Jakarta, Indonesia, Thursday, June 27, 2019. Indonesia's top court ruled Thursday against the former special forces general's challenge to the country's election results that alleged massive and systematic fraud, paving the way for incumbent Joko Widodo's second term as president. (AP Photo/Tatan Syuflana)
Losing presidential candidate Prabowo Subianto, left, speaks to reporters as his running mate Sandiaga Uno listens during a press conference in Jakarta, Indonesia, Thursday, June 27, 2019. Indonesia's top court ruled Thursday against the former special forces general's challenge to the country's election results that alleged massive and systematic fraud, paving the way for incumbent Joko Widodo's second term as president. (AP Photo/Tatan Syuflana)
Judges preside over the final hearing on the court challenge to the results of April's presidential election at the Constitutional Court in Jakarta, Indonesia, Thursday, June 27, 2019. Former Gen. Prabowo Subianto who lost to the incumbent President Joko Widodo claims there was massive electoral fraud and is asking the Constitutional Court to invalidate the election. (AP Photo/Tatan Syuflana)
Judges preside over the final hearing on the court challenge to the results of April's presidential election at the Constitutional Court in Jakarta, Indonesia, Thursday, June 27, 2019. Former Gen. Prabowo Subianto who lost to the incumbent President Joko Widodo claims there was massive electoral fraud and is asking the Constitutional Court to invalidate the election. (AP Photo/Tatan Syuflana)
Supporters of Indonesian presidential candidate Prabowo Subianto display a banner during a rally near the Constitutional Court where judges are expected to announce their decision on the court challenge to the results of April's presidential election, in Jakarta, Indonesia, Thursday, June 27, 2019. The former special forces general who lost to incumbent President Joko Widodo claims there was massive electoral fraud and is asking the Constitutional Court to invalidate the election. (AP Photo/Dita Alangkara)
Supporters of Indonesian presidential candidate Prabowo Subianto shout slogans during a rally near the Constitutional Court where judges are scheduled to announce their decision on the court challenge to the results of April's presidential election, in Jakarta, Indonesia, Thursday, June 27, 2019. Former Gen. Prabowo Subianto who lost to the incumbent President Joko Widodo claims there was massive electoral fraud and is asking the Constitutional Court to invalidate the election. (AP Photo/Dita Alangkara)