Nigerians have elected a new president, the first time an opposition candidate defeated an incumbent since the restoration of democracy in 1999. Despite his name, President Goodluck Jonathan’s political fortunes went bad. Muhammad Buhari, a 72-year-old former dictator and perennial presidential candidate, will take over on May 29.

Africa’s most populous nation with the continent’s largest economy faces more than its share of troubles: virulent Islamist insurgency, ineffective and brutal military, pervasive corruption, lost economic opportunities, government-created poverty. Despite seemingly good intentions and frequent heart-felt promises, Jonathan failed to solve these and other problems. After three failed presidential runs in a dozen years, Buhari won with a two million vote margin. His supporters celebrated, predicting good times ahead.

Success won’t come easily. Nigeria confronts most of the big challenges facing Africa. Instability and conflict were almost inevitable after independence came to a British colony with arbitrary boundaries which encircled antagonistic tribes and ethnic groups. Nigeria faces what has been called the resource curse—abundant oil which fueled a political spoils system and pervasive corruption. The country endured a bitter civil war and suffered under multiple military dictatorships, including one led by Buhari.

Nigeria enjoys the continent’s largest GDP but trails several African nations in per capita GDP. Globally Nigeria comes in as low as 150 out of nearly 200 countries. Although possessing extensive energy resources, the nation suffers from regular power outages, from which even the rich and powerful are not immune.

Nigerians are entrepreneurial but nearly a quarter of them are unemployed; youth joblessness is much higher. An intrusive, exploitative state blocks economic development and steals wealth. According to the latest Economic Freedom of the World Nigeria has one of the world’s least open economies, coming in at 125 of the 152 countries rated. Nigeria fails most dramatically on business regulation, legal system/​property rights, sound money, and free trade. Such policies discourage foreign investment in what should be the continent’s best market. Indeed, Kevin Daly of Aberdeen Asset Management told Forbes online columnist Chris Wright that such factors “have proved a toxic mix. Investors have pulled money from the country in their droves.” The Nigerian stock market is down by about a third from last year.

Corruption raises the cost of business and rewards economic manipulation and self-dealing. Last year an expatriate worker told me: “Nigeria is not a country. It is an opportunity.” Yet President Jonathan fired the head of the central bank after the latter complained that $20 billion in oil revenue was stolen annually. The recent drop in oil prices has exacerbated Nigeria’s economic problems. Before the crash petroleum represented 90 percent of the country’s exports and 70 percent of the government’s income.

Nigerian politics is anything but clean. Jonathan’s People’s Democratic Party ruled for 16 years, alternating Christian and Muslim candidates to overcome deep religious divides. The PDP used patronage and other tools of incumbency to maintain power. While the 2011 presidential election, in which Jonathan handily defeated Buhari, was considered generally free, the State Department noted that the poll was “marred by violence, fraud, and irregularities.” Some 800 people died in post-election violence.

Nigeria better protects political rights and civil liberties than many African states. However, restrictions and abuses remain common, especially at the state and local levels. The State Department pointed to a number of human rights challenges: “vigilante killings; prolonged pretrial detention; denial of fair public trail; executive influence on the judiciary; infringements on citizens’ privacy rights; restrictions on the freedoms of speech, press, assembly, religion, and movement; official corruption”; and more. Security personnel assaulted women and harassed journalists, who sometimes engaged in self-censorship. Prison conditions are awful. The judiciary is subject to political pressure. Abusive officials essentially enjoy immunity for their actions.

Insecurity is pervasive. Better hotels look like fortresses. Checkpoints interrupt major roads. No official or businessman of note travels alone. When I visited last year my group sported a well-armed escort. Companies build walls, man gates, and employ guards. Newspaper executives with whom I spoke said they could not safely send out trucks with the new edition overnight. The oil-rich Niger Delta is especially dangerous; executives admit to paying bribes to discourage attacks on their facilities, personnel, and ships.

Worse, sectarianism divides the nation. For most Nigerians other issues, from economics to crime, loom larger than religion. But an extremist minority uses violence to advance its ends. Nigeria is heavily Muslim in the north while Christianity predominates in the south. Several Islamic-majority states enforce Sharia law. At times sectarian violence has flared. While the national government does not persecute disfavored faiths, it “did not prevent detentions and restrictions affecting religious groups reportedly carried out by some state and local governments” and it “was also ineffective in preventing or quelling religious-based violence,” concluded America’s State Department.

In recent years the murderous Boko Haram (literally “Western education is forbidden”) extended its reach across Nigeria and declared its submission to the Islamic State. The group received a blaze of publicity last year after kidnapping hundreds of school girls, but its depredations are far wider and reach back far earlier. According to State, Boko Haram “sought to incite hostilities between Muslims and Christians in the northern and central states, where local laws, discriminatory employment practices, and fierce competition for land exacerbated ethnic and religious tensions.” The group attacks churches and mosques and murders freely—both Christians and Muslims who don’t want to slaughter Christians. The group has killed more than 20,000 Nigerians and displaced 1.5 million people in Nigeria and neighboring countries.

Government efforts against Boko Haram have been remarkably unsuccessful, at least until a recent multi-national campaign involving Benin, Cameroon, Chad, and Niger. The Nigerian military is underfunded and ill-trained, distrusted by civilian politicians for having staged multiple coups. Worse, government abuses generate support for Boko Haram. Noted State: actions by the security services “often increased the death toll, as bystanders were caught in crossfire during urban gunfights, security forces committed extrajudicial killings of suspected terrorists, and detainees died in custody.” The Jonathan government sacrificed Nigerians’ liberties without improving security.

Understandably, Nigerians desperately wanted change. Many are reading what they want into Buhari: he will revive the economy, create jobs, end corruption, and eliminate Boko Haram. He responded in kind: “Your vote affirms that you believe Nigeria’s future can be better than what it is today.” He added: “You voted for change, and now change has come.”

But in what direction? Buhari made few friends when in power—he lasted 20 months before being unseated by another general. TheEconomist observed: “He detained thousands of opponents, silenced the press, banned political meetings and had people executed for crimes that were not capital offenses when they were committed.” His soldiers even whipped people for arriving late at work.

Buhari says he now recognizes democracy to be the better option. And he may enjoy important advantages as president. Being a Muslim may better position him to combat Boko Haram, even as he emphasized secular governance and chose a Christian as his running mate. Buhari cultivated an austere image and reputation for probity—as dictator he targeted corruption. The former general also may be able to simultaneously reform and energize the military.

However, energizing the economy may prove more difficult. There is a lengthy transition until Buhari takes over on May 29, during which PDP elites might attempt to take final advantage of their influence. Worse, Yvonne Mhango of Renaissance Capital told Wright: “The stalling of economic activity under a first-term president tends to be protracted, as it implies a mostly new cabinet and potential restructuring of ministries and departments.” In fact, Buhari has not been in office for more than three decades and his party has never held power, which will make it more difficult to assemble a competent administration.

Yet candidate Buhari promised much. Worried Zoran Milojevic of Auerbach Grayson, Buhari “was talking utopia: new jobs for everyone.” While there are some free market advocates in Buhari’s coalition, more around him are not and he is thought to be an “unreconstructed statist,” according to the Financial Times. This is a prescription for economic failure. His previous record is cause for pessimism. Noted the Economist: “He expelled 700,000 immigrants under the illusion that this would create jobs for Nigerians. His economic policies, which included the fixing of prices and bans on ‘unnecessary’ imports, were both crass and ineffective.” Nigeria cannot afford a repeat performance.

Still, in at least one important respect the election was good news. The poll originally was scheduled for February and was delayed for six weeks, allegedly for security concerns. However, many Nigerians believed that the ruling party postponed the contest to gain more time to buy votes. Some Nigerians even doubted that the PDP would accept a loss. Yet despite some technical problems and concerns over electoral manipulation, the election went surprisingly well. Jenai Cox of Freedom House called the vote “one of the smoothest and least violent in Nigeria’s history.”

Equally important was President Jonathan’s unconditional acceptance of the results and speedy concession to Buhari. Although the former’s presidency was undistinguished, he took over under difficult circumstances—a Christian succeeding the Muslim incumbent who died after a secretive foreign hospitalization. More important, Jonathan left office honorably. “Nobody’s ambition is worth the blood of any Nigerian,” he said. After the poll he declared: “I promised the country free and fair elections. I have kept my word.” And he did.

Nigeria’s success suggests that the country has developed a lusher civil society and stronger commitment to the rule of law than often thought. Moreover, this experience offers hope for other African nations. Over the last two decades democracy has taken greater hold in the continent, but progress recently stalled. Roughly two dozen African nations are supposed to hold elections during the next 18 months. Observers fear that several of these votes are unlikely to be free and clean. Yet if as complicated and divided a society as Nigeria can overcome its many challenges to hold a peaceful election and host a democratic transfer of power, so can other African states.

Nigeria is a tragedy. Not so much because of the bad events which have occurred, which are many, but for its many lost opportunities and great unused potential. Unfortunately, governments in Abuja never seem to miss a chance to miss a chance. Hopefully this time Muhammad Buhari’s presidency will be different. The future of Nigeria, and Africa, depends on it.