Muhammadu Buhari has won Nigeria’s presidential polls, in the country’s first election victory by the opposition.
His party said his opponent, the incumbent President Goodluck Jonathan, conceded defeat and congratulated him.
Gen Buhari was ahead of Mr Jonathan by at least two million votes.
Observers have generally praised the election but there have been allegations of fraud, which some fear could lead to protests and violence.
However, a spokesman for Gen Buhari’s All Progressives Congress (APC) party praised Mr Jonathan, saying: “He will remain a hero for this move. The tension will go down dramatically.”
“Anyone who tries to foment trouble on the account that they have lost the election will be doing so purely on his own,” the spokesman added in quotes carried by Reuters.
Analysis: Will Ross, BBC Nigeria correspondent, Abuja
Finally the long wait is over. The opposition’s Gen Buhari has won this pivotal contest.
This is a hugely significant moment in Nigeria’s history. Never before has a sitting president lost an election and it feels as though Nigeria has turned a corner.
Since independence from Britain in 1960 there have been numerous coups and rigged elections. This poll has brought to the surface dangerous religious and regional differences. The outcome may be disputed by some and there is still a fear of violence.
But many Nigerians feel for the first time they have the power to vote out a government that is not performing well.
Results at 18:00 local time (18:00 GMT) showed Gen Buhari with 15 million votes, and Mr Jonathan with 12.8 million votes.
Mr Jonathan had led Nigeria since 2010, initially as acting leader before winning elections in 2011.
Nigeria has suffered from several attacks by the Islamist militant group Boko Haram, which has killed thousands of people in its drive to establish an Islamic state.
Many voters have said that they believe Gen Buhari is better positioned to defeat Boko Haram.