ABUJA (Reuters) - Muhammadu Buhari, who has won four more years as Nigeria's president, proved wrong those who doubted he could survive the blows of recession, militant attacks on oilfields and an Islamist insurgency that blighted his first term.
The former military ruler showed that his pledge to fight corruption remained popular, particularly when combined with promises to extend social welfare programmes aimed at feeding the poor and helping young people find work.
Experts had forecast a tough race against his main rival, Atiku Abubakar, a businessman and former vice president who sought to tap into discontent at unemployment and inflation by vowing to create jobs and double the size of Africa's biggest economy.
Buhari's comfortable victory caps a remarkable turnaround just two years after many thought the 76-year-old might not survive an undisclosed illness that had forced him to spend nearly half of 2017 being treated in Britain.
Buhari won 56 percent, compared with 41 percent for Atiku, the candidate for the opposition People's Democratic Party (PDP).
"The new administration will intensify its efforts in security, restructuring the economy and fighting corruption," Buhari said after the electoral commission declared him the winner.
A message on Buhari's Twitter feed showed a picture of him waving to supporters and the message "4+4" to mark his second four-year term.
The PDP said it did not accept the result. It had earlier accused the government of election-rigging, which it denied.
Buhari made history in 2015 as the first Nigerian to oust a president through the ballot box.
That victory marked a fresh chapter for a man who described himself as a "converted democrat" after years in the political wilderness following a stint as the head of a military regime in the early 1980s.
Born on Dec. 17, 1942 in Daura in Katsina state in the north, Buhari spent his career in the army. He seized power in 1983 as military ruler, promising to clean the stables of a mismanaged country but was removed after 18 months by another army general.
As military ruler, Buhari took a tough line on everything from the conditions sought by the International Monetary Fund to unruliness in bus queues, which he brought into line with soldiers armed with whips.
Three decades later, that intransigence emerged again in policies that prevented Nigeria from making a swift recovery from its first recession in 25 years, a slump caused by a collapse in oil prices and attacks on energy facilities by armed gangs looking for a slice of the country's hydrocarbon wealth.
The euphoria that saw his first election victory greeted by both Muslims and Christians - in a country split almost equally between the two religions - quickly turned to disappointment as the hoped-for injection of discipline failed to emerge.
Voters were prepared to overlook his advanced age and the admission that he was no economic expert, but they were less forgiving when he failed to seek expert advice to combat Nigeria's first recession in a generation.
Cuts to an amnesty package for former militants in the oil-producing Niger Delta, followed by the deployment of troops to the region, prompted a new round of attacks on energy facilities in 2016 that reduced oil production on which the country depended.
Faced with a slowing economy, Buhari applied the same tools that had failed when he was in power in the 1980s - keeping the currency artificially high as a matter of national pride.
That forced the closure of many businesses that relied on imported goods. His economic policies also meant international investors kept their distance from Nigeria.
His critics also called into question his strongest political asset, his military credentials, when Nigeria was hit by a series of security challenges: the Niger Delta oil attacks, an upsurge in clashes between herdsmen and farmers in the central states, and a resurgence in the Boko Haram Islamist insurgency in the north.
His re-election campaign had an inauspicious start when he was forced to deny rumours that he had died and been replaced by a lookalike from Sudan called Jubril.
However, even though his appearances at campaign rallies were often restricted to brief moments on stage when he waved to supporters but said little, audiences were large.
The crowds were particularly big in Buhari's northern heartland, where his anti-corruption message showed he retained the common touch that his tycoon opponent lacked.
That ability to mobilise his base proved to be crucial in carrying him to victory.
"One good term deserves another," said one of Buhari's campaign billboards. Despite the travails of his first term, enough voters agreed with that message.
(Editing by James Macharia and Giles Elgood)