In a televised speech, he said: "In tackling the insurgency, we have a tough and urgent job to do. Boko Haram will soon know the strength of our collective will. We should spare no effort until we defeat terrorism."

Much of Gen Buhari's support was in the north, in particular the north-east, which has suffered from Boko Haram's six-year insurgency. The militants have killed thousands of people in their drive to establish an Islamic state.

Many people accused Mr Jonathan of not taking Boko Haram seriously and thought Gen Buhari would be better positioned to defeat the militants.

Analysis: BBC's Will Ross in Lagos

This is a hugely significant moment in Nigeria's turbulent history. Never before has a sitting president been defeated in an election.

Since independence from Britain in 1960, there have been numerous coups and although the 2011 vote was an improvement, most elections have been rigged or even annulled by the military.

Of course in a relatively close election, there will be millions of people who are not pleased with the outcome. But the whole process is a sign that democracy is deepening in Nigeria and may be a tonic to other countries in Africa.

Nigerians can start to believe that it is possible to remove politicians through the ballot box.

He praised his defeated rival, saying: "I extend a hand of friendship and conciliation to President Jonathan and his team. I have no ill will against anyone. He has nothing to fear from me. He is a great Nigerian and still our president."

Pledging to uphold the rule of law, the former military ruler said: "Your constitutional rights remain in safe hands - you will be able to voice your opinion without fear of victimisation."

Image copyrightAPImage caption
Nigerians are continuing to celebrate the victory of Muhammadu Buhari

Gen Buhari pledged a government "that will listen to, and embrace, all", adding that "there shall be no bias or favouritism for any Nigerians".

He said: "Our nation faces many challenges - insecurity, corruption, economic decline. I pledge to give you my best in tackling these problems."

Earlier, US President Barack Obama said the polls had "shown the world the strength" of Nigeria's commitment to democracy.

He praised both Gen Buhari and Mr Jonathan for "their public commitments to non-violence throughout the campaign".

UN Secretary General Ban Ki-moon commended Mr Jonathan for "his statesmanship in upholding the democratic process" and said "the successful conduct of these polls [was] a testament to the maturity of Nigeria's democracy".

UK Foreign Secretary Philip Hammond said: "It is now important for both parties to ensure the transition to a new government remains peaceful."

More than 28 million Nigerians turned out to vote in the elections over the weekend. Gen Buhari beat Mr Jonathan by 15.4 million votes to 12.9 million.

Mr Jonathan said in an earlier statement: "I promised the country free and fair elections. I have kept my word."

He called on his supporters to stay calm, saying: "Nobody's ambition is worth the blood of any Nigerian."

Mr Jonathan's spokesman Reuben Abati told the BBC the president would remain in office until the handover date of 29 May.