(AFP) – He tried three times previously to become head of state since the return to civilian rule in 1999 and failed on each occasion.
But the straight-backed former major general, who overthrew elected president Shehu Shagari — widely seen as inept and corrupt — in a military coup in 1983, was determined to lead the country again.
He was given the chance when President Goodluck Jonathan conceded his loss, paving the way for the first ever peaceful transfer of power between political parties in the history of Africa's most populous country.
"Our country has now joined the community of nations that have used the ballot box to peacefully change an incumbent president in a ree and fair election," he said on Wednesday.
"To me this is indeed historic."
The shape his leadership will take is not yet clear but hopes are high he has the will to crack down on the country's endemic corruption.
He is due to be formally sworn in on May 29.
Buhari, 72, is "exceptionally corruption-free", one former senior military officer told AFP.
In the run-up to the vote he declared, "From the day we are sworn in as a government, anybody who abuses trust will be called to account."
Unusually for a Nigerian leader, the devout Muslim did not accumulate much in the way of spoils when he was in power, which was notable for its harsh anti-corruption stance.
His 20 months at the top also saw him fall foul of human rights groups, with critics of the regime thrown in jail, including the Afro-beat music legend Fela Kuti known for his outspoken lyrics.
Buhari was also at the centre of a major diplomatic row with former colonial power Britain after attempting to kidnap and smuggle Shagari's former adviser Umaru Dikko from London to Lagos.
Dikko, who had fled to the British capital after his boss was overthrown, was found drugged in a crate at Stansted Airport.
The British satirical magazine Private Eye lampooned the incident with one of its most famous headlines: "Fly Nigeria — It's a crate way to travel."
His election rival Goodluck Jonathan tried to use Buhari's authoritarian past against him during campaign, running warnings such as: "Once a tyrant, always a tyrant."
But Buhari brushed off the criticisms, acknowledging his past but referring to himself as a "converted democrat" ready to serve.
The former general has himself felt the sharp side of military rule.
He was ousted by Ibrahim Bagangida in a bloodless barracks coup in August 1985, and slipped out of public life.
But he made a return 20 years later as head of a government agency funding development projects with additional revenue from oil sales, where he demonstrated an autocratic but effective style.
"He is not very communicative, he is reticent but quite knowledgeable without flaunting it," said Ayo Banjoko, a Lagos-based political analyst.
"He is imbued with a messianic zeal. He has a rigid and intransigent disposition and he believes this country must and should be purged of its ills, especially corruption."
Buhari's quest for a return to high office saw him seek the presidency under two different political parties in 2003, 2007 and 2011.
He lost out to Olusegun Obasanjo, Umaru Musa Yar'Adua and Goodluck Jonathan respectively before standing again against the southerner.
Buhari complained of gross irregularities in all three polls but won a landslide victory in All Progressives Congress (APC) primaries to take on Jonathan again and the ruling People's Democratic Party.
But although billed by the APC as the man to rid Nigeria of endemic graft and end the Boko Haram insurgency, he has had to face multiple attacks from the administration in Abuja.
He has been portrayed as a religious zealot and it was claimed that he was ineligible to even stand as he could not initially prove that he had finished his secondary education.
But the APC has brushed off the claims as an attempt to divert attention away from the government's record.
In July 2014, Buhari narrowly escaped death after a suicide attack on his car as it travelled through the northern city of Kaduna: 42 people were killed and Boko Haram militants blamed.
Some analysts however suspect that the bombing may not have been the work of the militants, but a politically motivated hit.