The parliament was in session to discuss the impoverished country's budget when the building was targeted around noon (0900GMT, 5 a.m. EDT), Mogadishu Police Chief Abdi Hassan Awale said.
"The mortars were fired in the direction of the parliament building, but none of the mortars hit the parliament," Awale said. "They hit a residential area close by."
Resident Abdirahman Hassan described how "mortars started to rain down on our village."
"One of them hit a house, killing three children from the same family," he said. "In another place, two people were killed by the mortars."
Hassan said he counted 14 people injured in the explosions.
Somalia, an arid country on the Horn of Africa, has not had an effective central government in nearly 20 years.
Until January, the parliament had been based in the southwest town of Baidoa. Lawmakers were forced to return to the capital after Baidoa was captured on Jan. 26 by Al-Shabab, a hardline Islamic group which is on Washington's list of terror organizations.