Get breaking news alerts and special reports. The news and stories that matter, delivered weekday mornings.

KABUL, Afghanistan — Seven militants who targeted the Afghan parliament were killed early Monday after the building was rocked by a series of explosions, officials said.

A huge blast was followed by several smaller ones, Senator Nisar Haress told NBC News from a bunker inside the building.

Television stations were broadcasting live from parliament when the explosions occurred. Footage showed Afghan Speaker of the House Abdul Rauf Ibrahimi standing at a podium and calmly telling members of parliament that "an electric fault" appeared to be to blame.

Female Afghan lawmaker Qazi Rahela Saleem said one explosion knocked her off her seat.

The Morning Rundown Get a head start on the morning's top stories. This site is protected by recaptcha

Special forces troops were sent to the scene and a gunbattle raged for nearly two hours.

The incident began when a Taliban fighter driving a car loaded with explosives blew up outside parliament gates, Kabul police spokesman Ebadullah Karimi said. It was unclear how the driver got through several security checkpoints.

Taliban spokesman Zabihullah Mujahid said the militant group was behind the attack,

Kabul police chief Gen. Abdul Rahman Rahimi told local TV that all lawmakers were safe. The Health Ministry said that 31 civilians were wounded, including five women and three children.

A senior Kabul police official told NBC News that seven attackers were killed and buildings in the area were being cleared.

Taliban insurgents have launched complex attacks on government targets in the capital in the past, including the parliament.

Related: Taliban Splinters as ISIS Makes Inroads in Afghanistan

Afghan forces have struggled to fend off Taliban advances since the U.S. and NATO combat mission officially concluded at the end of last year.

Lawmakers chat outside the Afghan parliament building in this file photo taken in 2012. Christian Science Monitor / Christian Science Monitor via Getty File

Militant attacks in Kabul have risen in the past two months after a lull at the beginning of the year. The city of 3.5 million has never fully stabilized since a U.S.-led war ousted the hardline Islamist Taliban regime in 2001.

The insurgents have also been advancing across the country's north, capturing two districts of the Kunduz province in as many days.

Alastair Jamieson reported from London.