"The lawmakers and the other workers were rescued as soon as the car bomb exploded. But the terrorists are still firing from inside a mosque nearby," he added.
A Reuters witness who saw four bodies on the ground and one wounded man fleeing the scene said the fighting was ongoing.
Al Shabaab, the Al Qaeda-affiliated group that was pushed out of the capital about two years ago and has since waged a sustained guerrilla campaign, said it had launched the attack.
"We are behind the suicide bombing, explosions and the fighting inside the so-called Somali parliament house, and still heavy fighting is going on inside," Sheikh Abdiasis Abu Musab, al Shabaab's spokesman for military operations, told Reuters.
Since being ousted from Mogadishu, al Shabaab has intensified its attacks in Somalia and in neighbouring Kenya, which sent troops across the border to fight the Islamists. In September, the group killed 67 people in a shopping mall in the capital Nairobi.
In February at least 11 people were killed when it attacked the presidential compound.