Nigerian President Muhammadu Buhari has won a second term, according to officials who released the final vote tally Wednesday.

But his chief rival called the election a sham and vowed to challenge it in court.

Buhari, a former military general who is seen by many voters -- weary of the country’s rampant corruption -- as upstanding, had campaigned on a proposal to get rid of graft.

His rival, Atiku Abubakar, a business tycoon and former vice president, said the results reported for some states presented a “statistical impossibility,” according to the New York Times. His party is calling for recounts of results in four states.

“I hope and pray Nigerians will someday summon the courage to defend democracy,” he said, according to the Washington Post. “That is the only way we can move away from being the world headquarters for extreme poverty.”

Buhari, who is 76, said he was “deeply humbled” by the re-election, and urged Nigerians to come together.

“I will make a special appeal to my supporters not to gloat or humiliate the opposition,” he said. “Victory is enough reward for your efforts.”

SOUTH AFRICAN PASTOR FACING LAWSUITS OVER ALLEGED RESURRECTION

“Election is not war and should never be seen as a do-or-die affair."

Buhari received 15.1 million votes, or 55 percent, the electoral commission said. Abubakar got 11.2 million, or 41 percent. The average national turnout was 35.6 percent, continuing a downward trend.

One of Buhari’s most praised feats has been battling the militant Islamic insurgent group Boko Haram, which has killed more than 10,000 people and displaced millions of others.

While court challenges to elections are common in Nigeria, the Supreme Court has never overturned a presidential election, said Chris Kwaja, a senior adviser to the United States Institute of Peace.

The president’s colleagues had expected a challenge.

CLICK HERE FOR THE FOX NEWS APP

“There’s no opposition that will roll over and play dead," Hameed Ali, the ruling party agent attending the vote declaration, told reporters.

Violence marred the election, claiming at least 39 lives in several states, the Times reported. The Washington Post, however, reported that more than 250 people were killed in election-related violence.

During his campaign, Abubakar proposed an amnesty for officials who had been involved in corruption. He maintained that granting amnesty would be a way to recover billions he said corrupt officials had stashed overseas. Abubakar himself had been accused of corruption, including investing government funds in businesses in which they had interests.

The Associated Press contributed to this report.