Nigerians have celebrated their newly reinforced democracy, dancing, singing praises and releasing white doves as Muhammadu Buhari, the first candidate to beat a sitting president at the polls, became their president.
To roars of approval at the ceremony, Mr Buhari pledged to take personal charge of the fight against Boko Haram Islamic extremists and said he will root out human rights violations by the military - abuses that prevented full military co-operation from the US and Britain.
Mr Buhari, a 72-year-old former general who ruled briefly as a military dictator in the 1980s, calls himself a "born-again democrat" and has pledged to fight the endemic corruption that keeps a rich nation impoverished.
"We see him as our only hope against this crippling corruption," said Efo Okorare, curator of an open-air exhibition of portraits of Nigerian leaders, pointing out the many in military uniforms.
Mr Buhari saluted Nigerians, whether or not they voted for him.
"I belong to everybody and I belong to nobody," he said to applause. "I intend to serve as president to all Nigerians."
Nigeria is Africa's most populous nation with its biggest economy and is the largest oil producer, but government coffers have been hit by massive corruption, a devalued naira currency, low oil prices and a 63 billion US dollar (£41 billion) debt which grows as Nigeria borrows more to pay government salaries.
Some nervous politicians feared Mr Buhari's promise to retrieve ill-gotten gains signal a witch hunt. "These fears are groundless," the president said, though he said some of his predecessors had acted "like spoiled children, breaking everything in the house".
He promised to "ensure that the gross corruption" is checked.
Mr Buhari, resplendent in cream traditional robes, took the oath of office at Eagle Square in Nigeria's capital. The retired major-general then inspected troops in the plaza, decked out in colours of Nigeria's green and white flag, and waved to supporters from the back of an open vehicle.
A 21-gun salute boomed during the handover of power which is a turning point in Nigeria's democratic evolution.
Outside, people danced and sang "Sai baba, sai Buhari", meaning "Only father, only Buhari". Some swept the road with reed brooms, signalling Buhari's promised clean-up.
The newly elected government "is basking in a reservoir of (international) good will and high expectations", Mr Buhari said, promising to take advantage of it. "Nigeria has a window of opportunity to fulfil our mission as our great nation."
Kerry tweeted "Congratulations to @MBuhari & the Nigerian people. A privilege to be here to celebrate #Nigeria's historic & peaceful democratic transition."
Many African leaders attended the inauguration along with France's foreign minister Laurent Fabius and US secretary of state John Kerry.
Mr Kerry, accompanied by the commander of US Africa Command, General David M Rodriguez, was the first foreign official to meet Nigeria's new leader after the inauguration.
A senior US State Department official said Washington is ready to increase military aid and could quickly send more advisers.
Mr Buhari thanked the leaders of neighbouring Cameroon, Chad and Niger for contributing to a multinational offensive that this year has driven Boko Haram from towns where it had declared an Islamic caliphate.
Suicide bombings, abductions and hit-and-run attacks in northeast Nigeria continue by what he called "a mindless, godless group". The insurgency has killed more than 13,000 people and driven more than 1.5 million from their homes.
Mr Buhari said he will not consider the war won without rescuing those held hostage by the extremists, including more than 200 schoolgirls whose mass abduction last year prompted international outrage.
"This government will do all it can to rescue them alive," Mr Buhari said.
He blamed "official bungling, negligence, complacency or collusion" that allowed Boko Haram to become "a terrifying force".
Political science professor Richard Joseph, of Northwestern University, said Mr Buhari's victory is a sign of hope.
"The world desperately needs a victory against cultist jihadism. Nigeria (under Buhari) can provide it," he wrote in a blog.
Departing President Goodluck Jonathan last year halted US training of a battalion to fight Boko Haram. No reason was given but his officials had expressed anger at US refusals to sell Nigeria weapons including helicopter gunships.
The United States was hindered by a law preventing certain weapon sales to countries whose militaries are accused of gross human rights violations.
Nigeria's military is accused of killing detainees and civilians and burning their homes in revenge for Boko Haram attacks.
Mr Buhari addressed those concerns, promising to overhaul rules of engagement to prevent abuses and to take "disciplinary steps" against human rights violators.