In a historic moment for Africa’s most ­populous country, former dictator Muhammadu Buhari won Nigeria’s presidency on Tuesday, the first time in 16 years of democracy that an opposition candidate has defeated a sitting president.

Buhari, 72, will assume power in Africa’s richest nation at a time of crippling uncertainty — as public revenue shrinks because of the falling price of oil and the Boko Haram insurgency threatens the country’s northeast. He has fashioned himself as a populist who stands apart from a political class known for its ­exorbitant tastes and high-profile corruption scandals.

President Goodluck Jonathan called his rival to congratulate him Tuesday night, according to members of Buhari’s party. That message could be an important step toward limiting post-election violence; about 1,000 people were killed in disputes over the 2011 presidential contest. Nigeria’s election commission declared Buhari the winner early Wednesday. He received 15,424,921 votes to Jonathan’s 12,853,162.

For years, it appeared to many here that Jonathan’s People’s Democratic Party would rule Nigeria for the foreseeable future, thanks to a powerful patronage network and the use of electoral fraud. A sense of futility wore on Nigerians, particularly in the country’s embattled north, where for years Jonathan neglected the mounting Islamist insurgency and did little to develop the country’s poorest communities.

Although a former dictator is an unlikely messenger of democracy, Buhari, a northerner, responded to what many Nigerians have been pleading for. He is a retired general who has promised a concerted counterinsurgency campaign. He has a plan to end endemic corruption, albeit a vaguely articulated one.

Following his historic win, Muhammadu Buhari will take over a country wrestling with insurgency and financial troubles. (Reuters)

But mostly, he is renowned for his opposition to the ruling party — this was his fourth run for president in 12 years. Before now, he had never come close. By the time he gave his victory speech in Abuja, the capital, commentators on Nigerian television channels were talking about a “new Nigeria.”

While many Nigerians celebrated the opposition victory, some members of Jonathan’s party were embittered. In one of Tuesday’s most dramatic moments, Peter Godsday Orubebe, a former government minister, sat onstage during the official announcement of results, berating the electoral commission’s director for bias and interrupting the process.

It was an early sign of the political gulf that Buhari will have to navigate when he takes office May 29. The country is also divided by religion and geography: Jonathan is a Christian from the south; Buhari is a Muslim.

People in this country of 170 million had waited anxiously since Saturday’s vote for both the results and the public reaction to them. Supporters of each major party had threatened violence if their candidate lost. The military had been dispatched to areas of concern in preparation for unrest. With Buhari’s victory, many worried in particular about the Niger Delta, Jonathan’s birthplace, which has a history of militant activity.

Any post-election strife in that oil-rich region would not only affect a peaceful transfer of power but also hurt the government’s revenue stream. Thirty-five percent of Nigeria’s gross domestic product comes from oil and gas, according to the Organization of the Petroleum Exporting Countries.

Expectations for change

In this northern state, people celebrated in the streets, dancing, performing tricks on their motorcycles and screaming, “We need change.” They listed their expectations now that their party had finally won.

“The power supply will be constant,” said Ibrahim Abu Bakar, 45.

“Boko Haram will be defeated,” said Bello Mohammed, 30.

“Buhari will take care of unemployment,” said Nurudeen Mukhtar, 27.

Buhari has lived here for the better part of 30 years, since his military regime was overthrown in a coup. His faded two-story home was dark Tuesday night, but a guard invited a journalist to walk around.

“Look at that old car — that’s his only car,” said Sgt. Garba Abdullahi, who had been posted at Buhari’s gate by the Nigerian military. “He is a man of the people, not like the corrupt guys.”

In spite of the overwhelming expectations, it will be an enormous challenge for Buhari to implement rapid reform.

“Nigerians expect to see immediate change. They expect to see corruption end right away, but corruption is an institutional problem here. It is a way of life,” said Idayat Hassan, director of the Center for Democracy and Development, an Abuja-based think tank.

During his rule from 1984 to 1985, Buhari attempted to crack down on those he saw as guilty of corruption and malfeasance. He set up military tribunals that sentenced hundreds of suspected criminals and allegedly crooked politicians to prison, actions that some viewed as necessary but many others considered repressive. He also limited the news media’s freedom.

But Nigeria has evolved since Buhari’s regime, and it appears he has, too. Buhari has traded his pressed green military uniform for a traditional flowing robe. In a speech in London last month, he described himself as “a converted democrat who is ready to operate under democratic norms.”

Buhari has emphasized the need for secular rule and chose Yemi Osinbajo, a Christian pastor, as his running mate. But Buhari will still have to deal with Nigeria’s religious fault line, which has been reflected in sensational headlines about his plans to “Islamicize” Nigeria.

Buhari’s faith gained him no support among Islamist insurgents. He appeared to be a target in a large bombing here last year that was later attributed to Boko Haram.

Buhari has been deeply critical of Jonathan’s failure to defeat Boko Haram, which has grown steadily since 2009 in the absence of a coordinated military campaign, killing at least 10,000 people. Buhari also played up his background as “a military man,” suggesting that he would reform the country’s security forces.

In the past two months, a military operation involving Niger, Cameroon and Chad has chased the Islamist militants from many of their strongholds in the north. But Buhari will now have to ensure that the militants are flushed from their rural hideouts.

“Boko Haram has been driven out of certain towns. But they haven’t been defeated,” said former U.S. ambassador John Campbell, who is now at the Council on Foreign Relations.

On Monday, the United States and Britain warned that Nigeria’s election results “may be subject to deliberate political interference.” But any manipulation apparently did not make a significant difference in the outcome.

Jonathan had delayed the election for about six weeks at the request of military advisers planning an operation against Boko Haram. The move raised concerns about interference in the electoral process.

Jonathan surprised many here by conceding the election. His congratulatory call to Buhari was confirmed on Twitter by Aviation Minister Osita Chidoka.

Before the voting, Jonathan announced in a radio broadcast that Nigerians should “graciously accept” the election outcome.

“My sense is that demonstrations will take place, but the level of violence won’t be much,” said Chom Bagu, country director for the Search for Common Ground, a Washington-based group that works on conflict resolution. “There will be controlled demonstrations, and people will be directed to the courts.”