A gathering of Somali leaders has overwhelmingly backed a new constitution, paving the way for a new government to be elected this month.
The vote came shortly after two bombers blew themselves up outside the building.
Under a UN-backed plan, a new parliament will choose the next Somali leader on 20 August.
Somalia has been devastated by two decades of conflict and an al-Qaeda linked group controls many areas.
Its last functioning national government was ousted in 1991 and the anarchy has enabled both pirates and Islamist groups planning attacks around the world to set up bases in Somalia.
A leaked UN report recently said that 70% of aid to the country was unaccounted for but the interim authority strongly denied that corruption was rampant.
“This is an historic day – today we have witnessed the completion of a task that has been worked on for the last eight years,” said Constitutional Affairs Minister Abdirahman Hosh Jabril.
Of the 645 members of the constituent assembly present, 621 backed the document, 13 voted against while 11 abstained, reports the AP news agency.
The interim parliament must back the document before it takes effect.
A new group of MPs will then be selected, who will in turn choose a new president.
The two bombers were shot as they approached the building but still managed to detonate their explosive vests, officials say.
No-one else was killed but at least one guard was injured, they say.
African Union troops and the UN-backed government have forced al-Shabab out of Mogadishu but the al-Qaeda linked group frequently stages attacks in the city.
The Islamist militant group still controls many areas of southern and central Somalia.
One of the country’s most famous comedians, Abdi Jeylani Marshale, was shot dead by two unidentified men on Tuesday – he is to be buried shortly.
It is not clear who was behind the killing but last year he was threatened by al-Shabab.
He used to make people laugh by impersonating Islamist fighters.