Nigeria’s president has defended his sweeping win of a second term as free and fair and appealed to a “common love of country” as his top challenger vowed to go to court with allegations of fraud.

President Muhammadu Buhari was declared the clear winner by nearly four million votes as citizens of Africa’s largest democracy gave him another chance to tackle gaping corruption, widespread insecurity and an economy limping back from a rare recession.

While many frustrated Nigerians had said they wanted to give someone new a try, Mr Buhari, a former military dictator, profited from his upright reputation in an oil-rich nation weary of politicians enriching themselves instead of the people.

Top opposition candidate Atiku Abubakar, a billionaire former vice president who made campaign promises to “make Nigeria work again”, quickly rejected the result of what he called a “sham election”.

As many Nigerians awakened to the win along with the morning prayer, Mr Buhari told colleagues he was “deeply humbled”.

He regretted the loss of dozens of lives in “mindless” election-related violence.

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

Nigeria Election
Nigerian President Muhammadu Buhari (Jerome Delay/AP)

At a later event certifying his victory, he added to applause: “Election is not war and should never be seen as a do-or-die affair.”

He congratulated all candidates and the democratic process, “however contentious”.

In a statement shared by aides, challenger Mr Abubakar said he would have conceded “within seconds” if the vote had been free and fair.

Instead he alleged “manifest and premeditated malpractices” in many of Nigeria’s 36 states.

He asserted that voting was suppressed in his strongholds in the south and that states threatened by an extremist insurgency generated “much higher voter turnouts” than in peaceful ones.

He also objected to the deployment of the military in some areas.

Nigeria Election
A woman displays her voter’s card (Sunday Alamba/AP)

One domestic election observer, the Civic Media Lab, noted that “contrary to normal reasoning” the state most affected by extremist attacks, Borno, saw a 13% increase in voter turnout, even as overall turnout dropped.

Some residents had said, however, they were determined to vote despite the threat.

Court challenges are nothing new in Nigeria, where Mr Buhari himself doggedly fought his past election losses for months, in vain.

The Supreme Court of Nigeria has never overturned a presidential election, Chris Kwaja, a senior adviser to the United States Institute of Peace, said.

The president’s colleagues had expected a challenge.

Nigeria Election
Opposition presidential candidate Atiku Abubakar disputes the result (Sunday Alamba/AP)

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

Mr Buhari’s supporters began dancing in the streets of the capital, Abuja, on Tuesday night as victory became clear.

“He is a man of integrity,” a Buhari supporter in the northern city of Kano, Mohammed Aliyu, said as jubilant people held up four fingers to mark the new term.

“He is the only leader in Nigeria today that does not accumulate wealth.”

Mr Buhari received 15.1 million votes, or 55%, the electoral commission said.

Mr Abubakar received 11.2 million, or 41%.

The average national turnout was 35.6%, continuing a downward trend.