NOW HIRING: A mayor of Johannesburg.

DUTIES: Managing fickle governing partners. Dodging insults from opposition parties. And cleaning up piles of garbage.

LENGTH OF TERM: Likely very short.

This was once a city of dreamers, a gold town that seduced prospectors from all over hoping to strike it rich. Lately, though, Johannesburg has been something of a political punchline, a metropolis where many residents’ spirits are as dark as the streetlights.

This month, after days of brinkmanship and arm twisting, the city inaugurated its sixth different mayor in 22 months: Kabelo Gwamanda, a first-term city councilor from a political party that got just 1 percent of the vote in the last municipal election.

His ascent came after he won the majority of the votes of the city’s 270 elected council members. And it capped the latest chapter in a political soap opera where mayoral terms are measured in weeks and months, and where the inability of council members to stick with a leader has resulted in a municipal mess, with Johannesburg residents the biggest losers.

While political leaders bicker over power and cliques, exasperated residents often struggle through days without electricity and water, dodge cratered roads and fret about dilapidated buildings.

From a leather sectional in the safety of her $300-a-month, two-bedroom unit in the Elangeni Gardens residential complex, Pretty Mhlophe counts her blessings but also cringes at what city leaders have let fester.

Elangeni Gardens, developed in a public-private partnership in 2002 to address the city’s affordable housing shortage, boasts a patch of blue-and-green artificial turf, a jungle gym and a basketball court where children play freely. But the drab, boxy building across the street, once an apartheid government checkpoint for Black workers, is dripping with trash. It is so overcrowded with squatters that some have erected tin shacks in the back lot.

“Inside the complex it’s a home, outside the complex it’s scary,” Ms. Mhlophe, 42, said.

Many South Africans fear that what is unfolding in Johannesburg, official population of 5.6 million, could be a bad sign of what’s to come after national elections next year.

When no party earns more than half of the vote in an election in South Africa, parties seek to get above that 50 percent threshold by forming coalitions, which allow them to control the council and choose a mayor. In Johannesburg over the past two years, parties in ruling coalitions have on multiple occasions fallen out with each other, leading to the creation of new alliances that install a new mayor.

“This is childish,” Junior Manyama, a disgruntled member of the city’s — and country’s — largest political party, the African National Congress, said as he smoked a cigarette in his car outside of City Hall earlier this month, waiting for council members to elect a new mayor.

Mr. Manyama, 31, was furious that his party, with 91 seats on the council, agreed to a power-sharing arrangement that allowed someone from a party that holds just three seats to lead South Africa’s largest city.

“We can’t trust these people anymore,” he said, referring to political leaders.

For about two decades after the first democratic elections in 1994, South Africans did not have to worry about these on-again, off-again political romances because the A.N.C. dominated at the ballot box, nationally and locally. But the party has recently lost hold of many major municipalities.

Some analysts think it may slip below 50 percent in a national election for the first time next year, meaning the country’s president and other top leaders will have to be selected through one of these shaky coalition arrangements.

“It’s the worst case scenario playing out right now,” Michael Beaumont, the national chairman of ActionSA, the third largest party in Johannesburg, said outside the council chamber before the most recent mayoral vote. “I think the A.N.C. is going to actively campaign on the ticket of saying, ‘Better the devil you know than this kind of coalition mess.’”

Since its birth as a muddy mining camp that turned into a booming gold town, Johannesburg has struggled to serve all its residents. Home to one in 10 South Africans, the city is still battling to overcome apartheid’s impact, which led to urban flight and created vastly disparate worlds crammed into 635 sprawling square miles.

The highway connecting the northern suburbs to the southern townships winds past upscale malls and leafy communities where Spanish tiled roofs poke above high security walls. It passes over abandoned mine dumps yellow with gold dust, then past factories with darkened windows, before arriving in Soweto, where closely packed homes range from neglected workers’ hostels to sturdy bungalows with ornate pillars guarding the entrances.

Nearly half the city’s population lives beneath the poverty line. And the last time Johannesburg saw a major infrastructure boom was before the 2010 FIFA World Cup, with new bus lanes and paved sidewalks. By now, even those have deteriorated.

“A world-class African city,” reads the tagline on the municipal logo, and indeed Joburg — as it’s commonly called — can inspire with its energy.

Live music and festivals are aplenty. Fine-dining restaurants and roadside vendors serve up cuisines from around the globe. Theater and art exhibits can be part of the daily itinerary.

Not far from the Elangeni Gardens, trendy, gentrified markets speak to a vibrant city that many young people find attractive.

But those amenities can be of little consolation for Ms. Mhlophe and her neighbors, who have repeatedly called the police to report the thieves who have targeted their visitors and their cars, and the drug dealers loitering on the corner. Once, a woman was thrown from a fourth-floor window.

They have asked city housing officials to clean up the neighboring building, where trash sags on the second-floor eaves, and where on a recent afternoon a street vendor balancing a crate of oranges on her head had to skirt around a three-foot-tall trash heap to get into the building.

“We as the government have to provide services that are at least worth paying for,” Mr. Gwamanda, 38, said during his inauguration speech, bowed over a podium speaking softly.

He exchanged smiles and hugs and posed for pictures with fellow council members, including Dada Morero, who served 26 days as mayor last year.

“Let us collaborate in bringing back the heartbeat of the city of Johannesburg,” Mr. Gwamanda said.

He didn’t say how long that would take or whether he would be the mayor when it happens.