Former military ruler Muhammadu Buhari has become the first opposition candidate to win presidential elections in Nigeria.
Gen Buhari's party said his opponent, incumbent Goodluck Jonathan, had admitted defeat and congratulated him.
Mr Jonathan trailed Gen Buhari by about two million votes when he conceded.
Observers have generally praised the election but there have been allegations of fraud, which some fear could lead to protests and violence.
"President Jonathan called General Muhammadu Buhari, the winner of the elections, to congratulate him," Lai Mohammed, a spokesman for Gen Buhari's All Progressives Congress (APC), said.
The spokesman 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," he added.
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 most elections have been rigged.
Of course in a close election there will be many voters who are not pleased with this outcome but the whole process is a sign that democracy is deepening in Nigeria.
The poll has once again brought to the surface dangerous religious and regional differences and there is still a threat of violence.
The man who has been voted out, Goodluck Jonathan, has played a huge part today in trying to prevent that.
He made the phone call when there would no doubt have been some in his camp who would have preferred to dig their heels in.
Results at 6pm yesterday (local time) showed Gen Buhari with 15 million votes, and Mr Jonathan with 12.8 million votes.
Results have been declared in all states, except for Borno, which is viewed as one of the APC's strongholds.
Gen Buhari's supporters took to the streets in the northern cities of Kano and Kaduna, singing and dancing in celebration.
It is the fourth time the former military ruler, 72, has sought the presidency.
He ruled Nigeria from January 1984 until August 1985, taking charge after a military coup in December 1983.
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.