Militants in Somalia have attacked the country's parliament building with a multi-pronged strike involving a car bomb, a suicide bomber and gunmen on foot.

At least seven people were killed in the attacks in Mogadishu on Saturday morning, including six attackers and a soldier who tried to stop the suicide bomber from entering the building, police said.

Many members of parliament were inside the building at the time.

Gunfire and two blasts rang out near the building long after the attack began. Police have confirmed six attackers' deaths, including four men who were shot and killed by security forces. The driver of the car bomb and the bomber on foot also died.

Al-Shabaab, an al-Qaida-linked group, have claimed responsibility for the attack. The group has carried out several similar complex attacks in Mogadishu, including on the city's main court complex and attempts against the presidential palace.

Al-Shabaab was banned from the capital in 2011, but still controls wide areas of southern Somalia and have waged a sustained guerrilla campaign.