Upon winning independence from its British colonizers in 1960, thousands of Nigerians watched as their new green and white flag was raised over the capital at the time, Lagos, at midnight. As fireworks lit up the streets, hope and promise filled the air.

Nigerians’ hopes have been dashed many times since then. They have endured a bitter civil war, decades of military dictatorship and, in the past eight years, rising violence and economic failures under President Muhammadu Buhari. A record 89 percent of Nigerians think the country is going in the wrong direction.

But in this weekend’s presidential election — one of the most consequential in the 23 years since the last dictatorship ended and democracy took hold — many see a chance to change course.

And as Nigerians make their way on Saturday to polling stations across their huge and diverse country, the race to lead their young democracy and its legions of youthful citizens seems wide open.

The monopoly on power that the two major parties have held for two decades has been shaken up by a surprise third-party candidate, Peter Obi. Multiple polls have shown him in the lead, propelled by enthusiastic young voters, but whether they will turn out in large enough numbers to elect him is uncertain.

Other polls have shown both the governing party’s candidate, Bola Tinubu, and Atiku Abubakar, a businessman and perennial opposition candidate, in the lead.

In a country of 220 million, Africa’s most populous, more than 93 million people registered for permanent voting cards, the most ever, the election commission said.

On a recent afternoon outside an event hall in Lagos, one remorseful former Buhari voter, Joshua Pius, 34, a drummer on a break from performing, said he was now earning so little that his young family had been forced to cut back on food. His children are 1 and 3.

Mr. Pius was determined to make his next vote count, he said, as bouncy highlife music from a funeral streamed from the hall. Funerals in Nigeria are often celebrations of life rather than somber occasions.

He said, using the shorthand for the permanent voter’s card, “The only hope you have is your P.V.C.”

Like many Nigerians, Mr. Pius has been blindsided by a sudden countrywide shortage of cash — a crisis precipitated when the government decided to redesign and roll out new currency just before the election. Nigeria’s central bank took billions of naira (the local currency) out of circulation, while putting only a fraction in new notes back in. Even those with money in the bank cannot find cash to pay for food, medicine and other essentials, causing widespread suffering.

Sorting out that mess is just one of the mammoth tasks the election winner will face. G.D.P. per capita has plummeted during Mr. Buhari’s tenure. Oil production fell last year to its lowest point in over three decades. The army is deployed all over the country, fighting Islamist militants, secessionists, kidnappers and communal clashes.

But the potential of Africa’s biggest democracy is perhaps greater than the challenges. Nigerians speak proudly of their country’s natural riches: As well as oil, it has profuse supplies of gas and solid minerals, as well as greater agricultural potential than almost any other African country because of its vast, fertile lands and abundant water.

And that is to say nothing of its human capital. The country’s unofficial motto, “Naija no dey carry last” — pidgin English for “Nigerians never come last” — speaks to their drive and creativity, on display in the booming tech sector, the Nollywood film industry and the global musical phenomenon that is Afrobeats.

Recently, however, the young people who drive that innovation have been leaving in droves, or are making plans to.

One of those, Henry Eze, 31, a music producer, was on the sidelines of a political rally in Lagos this month, natty in a three-piece suit despite the heat. Mr. Eze said he left Nigeria for Europe in 2017, but ended up instead in a Libyan detention center, where he witnessed horrific abuses and had to bury dozens of his friends before he was rescued and brought home.

The rally he was attending was for Mr. Obi, who six months ago was not seen as a serious contender, but who has run a remarkably successful campaign, particularly online. He is the unexpected challenger against the governing party’s candidate, Mr. Tinubu, a former governor of Lagos, and Mr. Abubakar, the perennial opposition candidate. Of the 18 total candidates, a fourth candidate, Rabiu Kwankwaso, could prove a spoiler by splitting the vote in parts of the north.

Mr. Eze said that if Mr. Abubakar or Mr. Tinubu, whom he called “a vampire” for sucking the country’s riches, won the election, he would not hesitate to leave Nigeria again, even though he was traumatized by his first attempt to escape.

“Anywhere is better than Nigeria,” Mr. Eze said.

Many Nigerians think their leaders, also, cannot get much worse.

Some, like Mr. Eze, are putting their hopes in Mr. Obi. Others think Mr. Abubakar’s business acumen will help put Nigeria back on a prosperous path. Many support Mr. Tinubu, who has a reputation for spotting the talent and experience many say the country needs.

On the sidelines of a Tinubu rally this week, Bose Shoyombo, 32, a fashion designer, said, “We want jobs, and he’s the best positioned to help young people.”

All three of the front-runners — who have all faced accusations of corruption or wrongdoing — are promising several major departures from the way things have been done in the past: an end to the fuel subsidies that have helped push Nigeria into a fiscal hole and allowing the exchange rate to be set by market forces rather than officials.

For the first time, not one of the top contenders has a military background, a big deal considering former military rulers turned democrats have been at Nigeria’s helm for 16 of the 23 years since democracy was reborn in 1999.

For a country so youthful, with a median age of just over 18, politics is dominated by old men, in many ways playing by the old rules.

A well-known though murky phenomenon in Nigerian politics is the role of godfathers, a loose term for the “big men” who play an outsize role in making or breaking politicians’ careers.

Mr. Tinubu is one of the country’s best-known godfathers, boasting that he handpicked his successors as the governor of Lagos state. Mr. Tinubu even claims that without him, Mr. Buhari would never have become president.

This goes some way to explain the slogan coined by Mr. Tinubu and most often associated with his own presidential bid: “It’s my turn.”

Mr. Abubakar, of the main opposition party, has run and lost five times before. He could be forgiven for thinking it is his turn, too.

And at a recent visit to a Lagos market, Mr. Obi told the crowd: “If it is anybody to talk about ‘It’s my turn,’ it should be me,” a reference to the fact that there has never been a president from his region, the southeast.

Recently, other West African countries have experienced a wave of coups. Afrobarometer, a survey organization, noticed that several factors came together in the lead-up to those coups: dissatisfaction with the direction the country is headed, a lack of trust in the presidency, approval of the military, and a perception that corruption is increasing.

In Nigeria, the indicators are going that way too, according to the head of Afrobarometer.

On that last night of British rule in 1960, after the flag raising and the fireworks display ushering in their first day of independence, Nigerians waited for the dawn.

Often in the years since, analysts have predicted the disintegration of Nigeria, invoking the words of its most beloved writer, Chinua Achebe: “Things fall apart. The center cannot hold.”

So far, it has held.

Elian Peltier and Oladeinde Olawoyin contributed reporting.