Nigeria's Independent National Electoral Commission has declared opposition candidate Muhammadu Buhari the winner of Nigeria's presidential election.
Buhari, a retired major general, defeated incumbent President Goodluck Jonathan by about 2 million votes.
Earlier, Jonathan phoned Buhari on Tuesday to concede defeat.
The outgoing president also issued a written statement to his nation.
"I thank all Nigerians once again for the great opportunity I was given to lead this country, and assure you that I will continue to do my best at the helm of national affairs until the end of my tenure," he said.
"I promised the country free and fair elections. I have kept my word."
Buhari, 72, will take the helm of Africa's most populous nation at a critical time, as Nigeria grapples with the violent militant group Boko Haram.
A leader again
This won't be Buhari's first time leading Nigeria -- but it's his first time in nearly 30 years.
A military coup brought Buhari to power in late 1983, closing a brief period of popular rule by Shehu Shagari. But Buhari himself was ousted in another military coup in August 1985.
His presidential win comes after four attempts at leadership since he was ousted from power in 1985.
Buhari campaigned as a born-again democrat to allay fears about his strict military regime, while stressing that Nigeria's security needs to be the next government's focus.
His campaign was also fiercely anti-corruption. He ran under the slogan of "new broom," and his supporters were often pictured holding brooms in the lead-up to the vote.
Facing extremists
Nigeria's vote had been scheduled for February 14. But on February 7, Nigeria's election commission announced the vote would be postponed for six weeks due to security concerns, as the military needed more time to secure areas controlled by Boko Haram.
Jonathan has been criticized for not doing enough to combat Boko Haram, which is waging a campaign of terror aimed at instituting a stricter version of Sharia law in Nigeria.
On Saturday, residents in the northeastern state of Gombe said at least 11 people were killed and two more injured in attacks at polling stations, apparently by Boko Haram extremists.
Documentary filmmaker and African affairs analyst Ayo Johnson said earlier this month that the elections would come down to who could make Nigeria feel safe.
"Many Nigerians will not forget (Buhari) was a military leader during a dictatorship," Johnson said. "Or maybe they will feel that they need a military leader to address fundamental problems such as terrorism."
Buhari is a Sunni Muslim from Nigeria's poorer North, while Jonathan hails from a Christian and animist South that is rich with oil.
Ahead of this year's election, Jonathan and Buhari signed a nonviolence pact, the Abuja Accord, in January. On March 26 they renewed their pledge and reiterated their commitment to "free, fair and credible elections."
But violent protests broke out after polling on Saturday. Protesters fired gunshots and torched a local electoral office in Nigeria's oil-rich Rivers state on Sunday as they marched to protest the elections amid claims of vote-rigging and voter intimidation.