Nigerian president Goodluck Jonathan has called challenger Muhammadu Buhari to concede and congratulate him on his electoral victory, the country's aviation minister said.
The move paves the way for a peaceful transfer of power in Africa's richest and most populous nation.
Celebrations erupted all over Mr Buhari's strongholds in northern Nigeria and around his campaign headquarters in Abuja.
Car horns honked and people waved brooms in the air - a symbol of Mr Buhari's campaign promise to sweep out Nigeria's endemic corruption.
Mr Jonathan called Mr Buhari, 72, to congratulate him this evening, thus conceding defeat, aviation minister Osita Chidoka told the Associated Press. Mr Chidoka is close to the man who has governed Nigeria for the past five years.
Mr Jonathan was to make an address to the nation and Mr Buhari was preparing to address a news conference.
This is 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. Mr Jonathan's party has governed since decades of military dictatorship ended in 1999.
Mr Jonathan's concession comes before the final announcement of election results by the Independent National Electoral Commission.
Results of all but one of the 36 states and the Federal Captial Territory show Mr Buhari, a former military dictator, dealing a crushing defeat to Mr Jonathan.
Earlier, Mr Buhari's spokesman Garba Shehu told the Associated Press that Mr Buhari feared his victory could be stolen by "tricks" from the government.
Mr Jonathan's campaign has denied a warning from Britain and the United States that they suspected possible political meddling in the final tally of votes from Saturday's election.
On Tuesday evening, results from 35 states and the small Federal Capital Territory amounting to some 28 million votes showed Mr Buhari leading by two million votes. Mr Buhari is expected to carry the sole remaining state, north-east Borno, that is the birthplace of Boko Haram and has 1.4 million eligible voters.
Electoral officials broke off the count saying it would take up to two hours for Borno results to arrive.
Mr Buhari crucially carried Lagos state, Nigeria's commercial hub, with the largest number of voters, according to results announced on Tuesday though fewer than one third of voters participated.
Spontaneous celebrations sprang up across cities in northern Nigeria, where Mr 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, Mr Buhari delivered a crushing defeat to Mr Jonathan, winning 1.9 million votes to Mr Jonathan's 215,800.
Britain and the US warned on Monday of the possibility of political meddling in the final count. Mr Jonathan's campaign spokesman Femi Fani-Kayode said that was "absolute balderdash" and demanded evidence.
Mr Garba said the opposition party's agents at more than 150,000 polling stations across the country "tell us that we have won, but our victory is still threatened". The winning candidate must take more than half of all votes and at least 25% of votes in two-thirds of the 36 states and the Federal Capital Territory at Abuja.
The austere and strict retired general, who says he is a convert to democracy, has promised that if he wins he will stamp out an insurgency in the north waged by Boko Haram, a homegrown Islamic extremist group that has killed thousands of people, many of them civilians, has kidnapped even young girls, and has pledged fealty to the so-called Islamic State.
Critics and supporters agree that Mr Buhari is the one leader who did not treat the country's treasury as a personal piggy bank. During his brief 1984-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 Mr Buhari who dominate the north. Mr Buhari for the first time won states in the south west and even took one third of votes in a south-eastern state - an unprecedented development that some say reflects more of an anti-Jonathan than a pro-Buhari sentiment.
The vote counting in Abuja was disrupted by a representative of Mr Jonathan's party who protested that the proceedings were partial to Mr 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 has also complained that electoral officials are partisan. The count is being carried out in the presence of party representatives, national and international observers and media.
There have been delays in about a dozen states sending results to the counting centre 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 told AP.
Mr 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 Mr Buhari as a single candidate presented the first real opportunity in the history of Nigeria to oust a sitting president.
Mr Buhari was also able to count on considerable voter dissatisfaction with the performance of Mr 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.
Because of decades of military dictatorship, this is only the eighth election since the country won independence from Britain in 1960, and the fifth since democracy was restored in 1999.