"I declare Sharif Sheikh Ahmed the president of Somalia after  winning this election,"  Aden Mohamed Nur, the parliament speaker, said.

Rival withdraws

His other main rival, Nur Hassan Hussein, the prime minister, pulled out of the election following the first round.

Hussein, shaking Ahmed's hand after addressing the parliament, said: "I thank you very much and I am very hopeful everything will go smoothly and end as the people wish."

In depth

Timeline of Somalia
Restoring Somalia
A long road to stability
Profile: Sheikh Sharif
Sheikh Ahmed
"I am ready to co-operate with whoever is elected to make Somalia a peaceful country," he later said.

The parliament met in neighbouring Djibouti due to instability in Somalia.

Ahmed vowed to form a broad government and invited all armed groups in the war-ravaged Horn of Africa nation to  join the UN-sponsored reconciliation effort.

In a brief acceptance speech, he vowed to reach out to the former transitional government as well as to al-Shabab, an offshoot of the ICU which rejects talks.

"Very soon, I will form a government which represents the people of Somalia. We will live peacefully with East African countries and we want to co-operate with them," he said.

"I am extending a hand to all Somali armed groups who are still  opposed to this process and inviting them to join us," he said.

AU summit

The new president is expected to attend an African Union (AU) summit in Ethiopia during the weekend before returning to Somalia to put together a unity government.

Abdirahman Abdi Shakur, an advisor to the president's party, told Al Jazeera that security was one of the main issues and challenges.

"I would say that there will be huge challenges and at the same time opportunities," he said.

"We will reach out to every person in Somalia whehether it is al-Shabab or not, and we will try to persuade them to join the peace process.

"Our approach is reconciliation not confrontation and we try to speak to everyone wherever they are in our country."

"We will reach out to every person in Somalia whether it is al-Shabab or not, and we will try to persuade them to join the peace process"

Abdirahman Abdi Shakur, advisor to the new president's party

Under the constitutional charter, a new Somali president should be chosen by parliament within 30 days of the resignation of the former one.

Abdullahi Yusuf, the former president who accused by the international community of being an obstacle to peace, resigned on December 29 after four years in power.

The parliamentary vote, starting on Friday evening, came two days after 200 members of the opposition ARS were sworn into parliament as part of an agreement brokered by the UN.

Another 75 seats are still to be filled by other opposition and civil society groups, as part of an effort to bring former opponents into the government.

The parliament on Wednesday voted to extend by two years the transitional period of the government. Its original term of five years would have ended in seven months.

In the short term, the new president will have to deal with many armed opposition groups, including the al-Shabab, who have seized control of much of south and central Somalia, as well as large areas of the capital of Mogadishu.

Islamic law

Al-Shabab has vowed to carry on fighting and impose its interpretation of Islamic law throughout the country.

"Although there are strong expectations, we are all aware that years of war and violence, violations of human rights and corrupt practices will not disappear overnight," Ahmedou Ould-Abdallah, the UN's envoy, wrote in a letter to the Somali parliament.

"It is up to you, the fathers, mothers, brothers and sisters to prevail on your children, your young brothers and friends to stop the violence. For the last 20 years, it has not helped any group to win lasting victory," he wrote.

Somalia has not had an effective central government since 1991, when Mohammed Siad Barre was forced from power.