The victory writes a new chapter in the country's often turbulent history after six military coups since independence in 1960 and 16 years of unbroken civilian rule by Jonathan's party.
The gripping contest also capped a remarkable transformation for 72-year-old former army general Buhari, who led a tough military regime in the 1980s but now describes himself as a "converted democrat".
Thousands spilled onto the streets of northern Nigeria's biggest city, Kano, in celebration, shouting campaign slogan "Sai Buhari" ("Only Buhari") as he took an unassailable lead with one state to declare.
In another northern city of Kaduna -- the scene of rioting after the 2011 presidential election -- supporters of his All Progressives Congress (APC) chanted: "Change! Change!"
More From This Section
The Independent National Electoral Commission (INEC) said Buhari won 15,424,921 votes, or 53.95 percent, of the 28,587,564 total valid ballots cast.
Rival Jonathan, 57, of the Peoples Democratic Party (PDP), won 12,853,162 votes (44.96 percent) in the election held Saturday and Sunday.
INEC chairman Attahiru Jega said: "Muhammadu Buhari, of the APC, having satisfied the requirement for the law and scored the highest number of votes, is hereby declared the winner and is returned elected."
But with dissatisfaction rife over Nigeria's security, corruption and the economy faltering as oil revenues dived, voters turned out in force sensing an unprecedented opportunity for change.
In the financial hub of Lagos, in the southwest, Buhari supporters celebrated wildly, some of them on horseback, with fireworks exploding into the night.
"This is the first democratic change ever in Nigeria," Anas Galadima told AFP, as thousands thronged the APC headquarters in the capital Abuja, dancing and banging drums.