President President Sharif Sheikh Ahmed, who has been in power since 2009, unsuccessfully sought re-election.

Read a version of this story in Arabic

Story highlights

NEW: White House calls for "a new era of governance" from Somalia's leaders

Hassan Sheikh Mohamud will serve a four-year term

The political newcomer has worked for the United Nations and is a former university lecturer

Somalia has not had an effective central government in decades

CNN  — 

Somali lawmakers voted for a new president Monday, a key milestone for the war-torn nation as it establishes its first stable central government in decades.

Parliament members picked Hassan Sheikh Mohamud, a political newcomer who has worked for the United Nations and several international organizations.

The new president, who also served as a university professor, defeated the incumbent and some two dozen other candidates.

The vote marks a milestone for the nation, which plunged into chaos after Dictator Mohamed Siad Barre was overthrown 21 years ago. Following his ouster, clan warlords and militants battled for control, sparking a civil war and mayhem nationwide.

Somalia has not had an effective central government since then and has mostly remained under a shaky transitional federal government.

“Somali people have taken a great step forward on the path to peace and prosperity,” said Augustine P. Mahiga, the U.N. envoy to the nation. “Today, Somalia’s parliamentarians — in a calm, dignified and contemplative manner— ended the transitional period decisively. Somalia has proved the doubters wrong and sent a powerful message of progress to all of Africa and indeed to the entire world.”

The vote is the latest in a series of political transitions in the nation.

In recent weeks, it has adopted a provisional constitution, selected members of parliament and appointed that body’s speaker.

“It has not been easy getting us to this point,” Mahiga said. “There have been moments when all seemed lost and we have sometimes been on the brink of despair.”

The White House congratulated the new president and called on Somali leaders “to usher in a new era of governance that is responsive, representative and accountable.”

“The United States calls on the international community to reaffirm its commitment to Somalia, and to help realize a more secure and prosperous future for the Somali people,” it said in a statement.

Candidates in Monday’s parliamentary vote included outgoing President Sharif Sheikh Ahmed, who has been in power since 2009, and his prime minister. Both have been accused of failing to crack down on corruption and Islamist militants in the nation.

Over the years, gunbattles between militants and government troops became a common fixture in the capital of Mogadishu, forcing lawmakers to meet in neighboring nations for security reasons.

Somalis have fled in record numbers, and are living as refugees in nearby nations.

Somalia’s problems have elevated into worldwide concerns as neighboring nations struggled to contain the influx of refugees and the instability fueled the growth of Islamist insurgents.

This is the first time Somali politicians have picked a new leader at home because of security concerns, according to Hamza Mohamed, a Somali analyst based in London.

“Previous elections were held in Djibouti and Kenya,” he said. “Because of this, Somalis feel they’re part of the process this time even though they’re not voting in the president.”

Despite the move toward a more permanent government, challenges remain. Large parts of the country are under the control of militants and pirates.

And even though insurgents have fled the capital and guns have fallen silent, portions of the nation remain lawless.

African Union and Somali troops are battling Al-Shabaab militants, an al Qaeda-linked group that controls part of the nation’s south. The militant Islamist group has waged an insurgency against the weak transitional government since 2007

In recent months, the troops have driven the militants out of Mogadishu, and the capital is slowly trickling back to normalcy. Coalition forces are exerting control in more areas, but the nation was not secure enough to hold a nationwide vote.

“The transition is over. Somalia must now focus on stabilization, reconciliation and building sustainable and accountable institutions of governance capable of providing services to its people,” Mahiga said in a statement.

The new president will serve a four-year term.