Amid anger over an Islamist insurgency that has claimed thousands of lives, Nigerians returned a 72-year-old former military dictator to power Tuesday in the most hotly contested election in the country's history.

Incumbent Goodluck Jonathan conceded defeat to Muhammadu Buhari, a Cabinet minister close to the outgoing president told The Associated Press, paving the way for an unprecedented peaceful transfer of power in Africa's most populous nation.

Supporters of opposition candidate Muhammadu Buhari, one bound in mock chains, celebrate an anticipated win for their candidate in Kano, Nigeria, on March 31, 2015. (Ben Curtis/Associated Press) It will be the first time in Nigeria's history that an opposition party has democratically taken control of the country from the ruling party — a sign of the West African nation's maturing young democracy. Jonathan's party has governed since decades of military dictatorship ended in 1999.

Celebrations erupted all over Buhari's strongholds in northern Nigeria and around his campaign headquarters in Abuja. Cars honked and people waved brooms in the air — a symbol of Buhari's campaign promise to sweep out Nigeria's endemic corruption.

Jonathan called Buhari to congratulate him Tuesday evening, thus conceding defeat, Aviation Minister Osita Chidoka said.

Jonathan's concession came before the final announcement of election results by the Independent National Electoral Commission and as both he and Buhari prepared to address the nation.

Jonathan urged his supporters to follow "due process" in chanelling their frustrations at losing this weekend's election, trying to pour cold water on any potential post-vote violence.

"Nobody's ambition is worth the blood of any Nigerian," he said in a statement issued after his election defeat. "The unity, stability and progress of our dear country is more important than anything else."

Won by 2.4 million votes

Results of all but one of the 36 states and the Federal Capital Territory showed Buhari, a former general who ruled with an iron hand during a brief tenure in the 1980s, dealing a crushing defeat to Jonathan.

Buhari, right, with Jonathan a few days before the presidential election. (Stringer/Reuters)

He won overwhelmingly in the final state to report results, northeastern Borno, the birthplace of the brutal Islamic insurgent group, Boko Haram, and the one that has endured the worst suffering from the Islamic uprising that has swept through villages and towns in the north, killing thousands of civilians and kidnapping many more, including hundreds of schoolgirls.

An Associated Press count of the final results showed Buhari winning more than 15.3 million votes to Jonathan's 12.9 million. Buhari won 19 states to Jonathan's 17 states and the small Federal Capital Territory. Final official results were expected to be announced late Tuesday.

Besides dominating, as expected, in his northern strongholods, Buhari crucially carried Lagos state, Nigeria's commercial hub with the largest number of voters, though fewer than one-third of eligible voters participated. He also took other critical competitive states in the country's southwest.

The victorious candidate must take more than half of all votes and at least 25 percent of votes in two-thirds of the 36 states and the Federal Capital Territory at Abuja.

Spontaneous celebrations sprang up across cities in northern Nigeria, where Buhari is almost revered. Young men on motor scooters performed wheelies as hundreds of youths chanted, "Change! Change! Change!" and cars honked their horns in support. In Kano state, Buhari delivered a crushing defeat to Jonathan, winning 1.9 million votes to Jonathan's 215,800.

Outside Buhari's party headquarters in Abuja, women chanted songs and used grass brooms to elaborately sweep the way ahead of arriving dignitaries in flamboyant robes.

Belated convert to democracy

The austere and strict Buhari has described himself as a belated convert to democracy, promising that if elected, he would stamp out the insurgency in the north waged by Boko Haram, the homegrown Islamic extremist group that has pledged fealty to the Islamic State group.

If indeed Buhari becomes president, it sends a clear message to the people in government that you cannot take the people of Nigeria for granted and that Nigerian democracy is maturing. — Kadaria Ahmed, journalist and political analyst

Critics and supporters alike agree that Buhari is the one leader who did not treat the country's treasury as a personal piggy bank. During his brief 1983-1985 dictatorship he ruled with an iron fist, jailing people even for littering, and ordering civil servants who arrived late to work to do squats. He gagged the press and jailed journalists to cover up a deepening economic crisis as prices tumbled for the oil on which Nigeria's economy depends. He eventually was overthrown by his own soldiers.

Nigeria's 170 million people are divided almost equally between Christians mainly in the south and Muslims, like Buhari, who dominate the north. In this election Buhari for the first time won states in the southwest and even took one-third of votes in a southeastern state — an unprecedented development that many say was more a reflection of voter antipathy toward Jonathan than pro-Buhari sentiment.

Buhari's showing in his fourth bid to become president was boosted by the formation of a coalition of major opposition parties two years ago. Its choice of Buhari as a single candidate presented the first real opportunity in the history of Nigeria to oust a sitting president.

Buhari also was able to count on considerable voter dissatisfaction with the performance of Jonathan, who has been president since 2010.

"If indeed Buhari becomes president, it sends a clear message to the people in government that you cannot take the people of Nigeria for granted and that Nigerian democracy is maturing," said journalist and political analyst Kadaria Ahmed.

She cited Jonathan's perceived insensitivity to the suffering of citizens caught up in the mayhem of Boko Haram's uprising, in which some 10,000 people were killed last year and more than 1.5 million people have been driven from their homes, as stoking opposition to his re-election.

Vote-counting delays

The Nigerian military, with help from regional troops, forced Boko Haram out of areas the insurgents had taken in recent months as they formed their self-styled "caliphate."

Buhari's victory is the first time that an opposition party has democratically taken control of Nigeria from the ruling party. (Ben Curtis/Associated Press)

There were vote-counting delays in about a dozen states because of logistical challenges that had election material being delivered by air, road, speedboat, mules and camels, spokesman Kayode Idowu of the Independent National Electoral Commission said.

In Abuja, the count was disrupted Tuesday by a representative of Jonathan's party who protested that the proceedings were partial to Buhari.

"We have lost confidence in you. You are tribalistic! You are partial!" shouted former Cabinet minister Peter Godsday Orubebe to the chairman of the electoral commission counting the vote.

The opposition also complained that electoral officials were partisan. The count was being carried out in the presence of party representatives, national and international observers and media.

Because of decades of military dictatorship, Saturday's vote was only the eighth election since the country won independence from Britain in 1960, and the fifth since democracy was restored in 1999.