Attackers detonated a huge car bomb outside the gates, stormed the compound, then entered a building next to the chamber.
Police evacuated the premises, while trying to fight the gunmen off.
The Taliban say they carried out the attack to coincide with a vote to endorse a new defence minister.
The spokesman for the interior ministry, Sediq Seddiqi, said the gunmen had attempted to storm the parliament building itself after the gates were breached by the suicide bomb.
They were fought off and entered a building under construction next to parliament. MPs were showered with broken glass, and the chamber filled with smoke as the fighting went on. It took nearly an hour before all the firing stopped.
At least 18 people are reported to have been wounded. Mr Seddiqi said no MP had been injured.