MOGADISHU, Somalia — In a fortified tent guarded by peacekeeping forces, hundreds of lawmakers elected a new president in Somalia on Sunday, capping a violent election season that threatened to push the Horn of Africa nation toward a major breakdown.
The selection of Hassan Sheikh Mohamud, a former president, in Mogadishu ended a bitter election period marred by corruption, a president’s attempt to cling to power and heavy fighting in the streets. Mr. Mohamud defeated three dozen candidates after three rounds of voting, including President Mohamed Abdullahi Mohamed, who drew condemnation after extending his term last year.
The vote, which had been delayed for nearly two years, came amid soaring inflation and a deadly drought that has left almost 40 percent of the country hungry. The streets in Mogadishu, the capital, were closed on Sunday, and the police announced a curfew that would last through Monday morning.
Ululations and cheers erupted in the lawmakers’ tent after Mr. Mohamud was declared winner. Celebratory gunfire erupted in parts of the capital, according to witnesses. Earlier in the day, several loud explosions could be heard near the fortified compound where the vote was held, but it did not disrupt the process.
The new leader, who was immediately sworn in, will face a host of challenges in his four-year term.
Somalia, a nation of 16 million people, has suffered for decades from civil wars, weak governance and terrorism. Its central government has been bolstered by African Union peacekeepers and Western aid, including billions of dollars in humanitarian support and security assistance from the United States, which has sought to keep Somalia from becoming a haven for terrorists.
The president was chosen by 328 lawmakers, who were picked by clan representatives. Mr. Mohamud garnered 214 votes to Mr. Mohamed’s 110. A few votes were spoiled and a sick lawmaker was excused.
Mr. Mohamud, who was president from 2012 to 2017, was born in 1955 in the central Somali region of Hiran, according to an official biography on his website. A peace activist and educator, he co-founded a college that became one of Somalia’s largest.
Mr. Mohamud succeeds Mr. Mohamed, a former U.S. citizen and bureaucrat, who led the country for five years. Mr. Mohamed has been accused of cracking down on the opposition and on journalists, fomenting a rift with neighboring Kenya and undercutting the power-sharing model that buttressed the country’s federal system.
The Shabab, a terrorist group linked to Al Qaeda, have exploited the political instability and the bitter divisions between security forces to grow its tentacles, experts said. After more than 16 years, the group now has a firm grip on much of Somalia — extorting taxes, judging court cases, forcing minors into its ranks and carrying out suicide bombings.
In the weeks before the vote, the group killed civilians including at beachside restaurants, mounted a major offensive on an African Union base — killing at least 10 peacekeepers from Burundi — and sent suicide bombers to jump on the cars of government officials.
In interviews with more than two dozen Somali citizens, lawmakers, analysts, diplomats and aid workers before Sunday’s vote, many expressed concern about how the deteriorating political, security and humanitarian conditions had reversed the few years of stability achieved after Al Shabab were kicked out of the capital in 2011.
“These were five lost years, ones in which we lost the cohesion of the country,” Hussein Sheikh-Ali, a former national security adviser to Mr. Mohamed and the chairman of the Hiraal Institute, a research center in Mogadishu, said of Mr. Mohamed’s presidency.
The protracted political battles, particularly over the elections, undermined the government’s ability to deliver key services, observers say, even as it achieved debt relief and pushed to join the global financial system. Critics and opposition figures also accused President Mohamed of trying to keep power at all costs, exerting pressure on the electoral commission, installing state leaders who would help sway the election and trying to fill Parliament with supporters using the intelligence agency.
Last year, when he signed a law extending his tenure by two years, fighting broke out in the capital’s streets, forcing him to change course.
Observers said the election of lawmakers last year was rife with corruption.
Abdi Ismail Samatar, a first-time Somali senator and a professor at the University of Minnesota who researches democracy in Africa, said this election cycle could be ranked as “the worst” in Somalia’s history.
“I don’t think I could have ever imagined how corrupt and self-serving it is,” Mr. Samatar said, adding, “I saw people being given money in the election for the speakership right in front of my face in the hallway.”
Larry E. André Jr., the U.S. ambassador to Somalia, said that the majority of the legislative seats had been selected by regional leaders, “sold” or “auctioned.”
The United States imposed visa sanctions in both February and March on Somali officials and others accused of undermining the parliamentary elections, which eventually concluded in late April.
Because of the indirect nature of the presidential vote, candidates did not shake hands with citizens or campaign in the streets. Instead, they met with lawmakers and clan elders in luxury hotels and compounds guarded by soldiers and blast walls. Some aspirants put up election billboards, promising good governance, justice and peace.
But few in this seaside city believe politicians will make good on their pledges.
“Everyone wears a suit, carries a briefcase and promises to be as sweet as honey,” said Jamila Adan, a political science student at City University. “But we don’t believe them.”
Her friend Anisa Abdullahi, a business major, agreed, saying those running for office could not identify with ordinary Somalis’ daily tribulations.
“They never make people feel like the government comes from the people and is supposed to serve the people,” she said.
Given the government’s infighting and paralysis, many Somalis are asking whether a new administration will make a difference.
Some Somalis have turned to the Shabab for services that would ideally be delivered by a functioning state. Many in Mogadishu regularly travel to areas dozens of miles north of the city to get their cases heard at Shabab-operated mobile courts.
One of them is Ali Ahmed, a businessman from a minority tribe whose family home in Mogadishu was occupied for years by members of a powerful tribe. Mr. Ahmed said the Shabab-run court ruled that the occupiers should vacate his house — and they did.
“It’s sad, but no one goes to the government to get justice,” he said. “Even government judges will secretly advise you to go to Al Shabab.”
Traders pay taxes to the Shabab, fearing threats to their businesses and lives.
“While the government is busy with itself, we are suffering,” said Abdow Omar, who runs a business importing flour and sugar in the capital, and pays the militants about $4,000 a year. “The Shabab are like a mafia group. You either have to obey them or close your business. There’s no freedom.”
Some officials admit the government’s shortcomings. Al Shabab have been able to widen their tax base because “elected officials were too busy politicking instead of doing policy work,” said one government official who spoke on the condition of anonymity because of lack of authorization to speak to the news media.
Sunday’s election came as parts of Somalia faced the worst drought in four decades. Some six million people are extremely short on food, according to the World Food Program, with nearly 760,000 people displaced.
Almost 900,000 of those affected live in areas administered by Al Shabab, according to the United Nations. Aid organizations are not able to reach them there, crops are failing and the Shabab demand taxes on livestock, according to interviews with officials and displaced people.
To find food and water, families travel hundreds of miles, sometimes on foot, to cities and towns like Mogadishu and Doolow in the southern Gedo region. Some parents said they buried their children on the way, while others left weak children behind to save others who were hardier.
Dealing with the Shabab will be among the first challenges facing Somalia’s next government, said Afyare Abdi Elmi, executive director of the Heritage Institute for Policy Studies in Mogadishu.
But the new leader, he said, needs also to deliver a new Constitution, reform the economy, deal with climate change, open dialogue with the breakaway region of Somaliland and unite a polarized nation.
“Governance in Somalia became too confrontational over the past few years,” Mr. Elmi said. “It was like pulling teeth. People are now ready for a new dawn.”