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.
Pictures on social media showed parliament full of smoke and people running for cover.
Even by Afghan standards, these were very dramatic scenes, and police had a complex operation on their hands, says the BBC’s David Loyn in Kabul.
The Taliban were extracting maximum propaganda advantage by doing it on the day that parliament was meeting to consider the appointment of new Defence Minister Massoom Stanekzai, our correspondent says.
Local media reported another explosion in the Dahmazang area of Kabul city.
The Taliban have launched complex attacks on government buildings in the capital in the past.
They have made substantial gains recently in Helmand in the south-west, and have been advancing across the north of the country, capturing two districts of the Kunduz province in recent days.
Militant violence has increased across the country since the departure of most US and Nato forces last year.