Taliban militants attacked Afghanistan's parliament Monday, detonating a suicide car bomb at an entrance and sending gunmen to storm the building, engaging security forces in a gunfight that left two dead, as lawmakers inside voted to endorse a new defense minister.

Afghan security forces managed to repel the attack, killing all seven gunmen and ensuring that no members of parliament were harmed. But the audacious assault on one of the most heavily guarded compounds in the capital came as the Taliban captured two northern districts in as many days, displaying their ability to operate on multiple fronts.

Interior Ministry spokesman Sediq Sediqqi said the attack began with a car bomb explosion near the entrance. The gunmen then attempted to storm the compound but were pushed back by security forces and eventually took refuge in a nearby building under construction.

Sediqqi later said all seven attackers were killed by police. He said no members of parliament were wounded in the incident. "It is over now," he said.

A civilian woman and a 10-year-old girl were killed, Sediqqi said, and Health Ministry spokesman Mohammad Ismail Kahousi said 31 civilians were wounded in the attack.

More On This...

Sidiqa Mubarez, a member of parliament, said the building was rocked by a large explosion and that some people were wounded by flying glass. She said the explosion happened shortly after Masoom Stanekzai had arrived to be confirmed as defense minister, a post that has been vacant for nine months.

The Taliban claimed the attack. The militant group's spokesman, Zabihullah Mujahid, told The Associated Press by telephone that it targeted Stanekzai and the parliament itself. He said the assault showed the "capability of the mujahedeen, who can even attack the parliament in the capital."

Afghan President Ashraf Ghani strongly condemned the assault. "Targeting innocent people in the holy month of Ramadan is a clear act of hostility against the religion of Islam," his office said in a statement, adding that the perpetrators "are criminals who are bound by no creed or religion."

An Associated Press reporter heard heavy gunfire outside the parliament and saw black smoke billowing from the entrance as ambulances raced to the scene. The reporter later heard sporadic shooting from the building where the militants were said to be holed up.

Just down the street, hundreds of children were evacuated from a school.

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

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

Mohammad Yusuf Ayubi, head of the provincial council, said the insurgents attacked the district of Dashti Archi from four sides, setting off heavy fighting before seizing full control of the area early Monday. He said local forces suffered casualties but did not have a precise count.

He said around 150,000 residents of the district were unable to leave.

The Taliban confirmed that they had captured the district, as well as ammunition and four tanks, in an emailed statement.

The Taliban seized control of the Chardara district in Kunduz on Sunday. The insurgents attacked the provincial capital, also called Kunduz, in a surprise attack in April and nearly captured the city before Afghan forces pushed them back.

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.  More than 2,300 Afghan soldiers, police and pro-government fighters have been killed since the start of the year -- more than the total number of U.S. troops killed since the 2001 invasion that ended Taliban rule.

The Associated Press contributed to this report.