The opposition had called on the interim government, led by Sharif Sheikh Ahmed, to implement the sharia as a precondition to start a national dialogue in the war-torn country.
Ahmed had pledged to form an inclusive government after being elected president in January.
Analysts say that the move to implement sharia is an attempt by political leaders to re-assert government control over southern and central parts of the country.
Mohamed Sheikh Nor, a Somali journalist, told Al Jazeera: "They all hope that this will leave Somalia to recover from years of destruction and setback.
"Also, powerful Islamic powers have given a strong backing to the vote and called upon all insurgents to stop the fighting against the government."
Al-Shabab, an anti-government armed group, had already implemented sharia in areas under its control.
Somalia has been without an effective central government since 1991, when Mohamed Siad Barre was forced from the presidency.