Taliban militants attacked the Afghan parliament on Monday, with gunfire and explosions rocking the building, sending lawmakers running for cover in chaotic scenes relayed live on television.

The insurgents tried to storm the complex after triggering a car bomb but were repelled and have taken position in a partially-constructed building nearby, officials said of the ongoing attack.

All Members of Parliament were safely evacuated after the attack, which came as the Afghan president's nominee for the crucial post of defence minister was to be introduced in parliament.

The assault on such a high-profile target in downtown Kabul raises fresh questions about security as Afghan forces battle a resurgent Taliban for the first time without the aid of NATO forces, who ended their combat mission in December.

"First a car bomb detonated on the main road near the parliament building, then a group of attackers entered a building in front of parliament," Kabul police spokesman Ebadullah Karimi told AFP.

"Afghan special forces are fighting them now. All the MPs have been safely evacuated."

MP Mohammad Reza Khoshak, who was in the chamber at the time, described the moment the blast struck.

"The session was on and we were waiting for defence minister nominee... Suddenly we heard a loud explosion, followed by several other smaller explosions," he told AFP.

"In a few seconds the hall was filled with smoke and MPs began fleeing the building. The militants are still firing at the building and clashing with security forces."

The Taliban launched a countrywide offensive in late April, stepping up attacks on government and foreign targets in what is expected to be the bloodiest fighting season in a decade.

The militants recently rebuffed requests from senior Afghan clerics to halt attacks during the fasting month of Ramadan even as a surge in violence has sent civilian casualties soaring.

A group of suicide attackers last tried to storm parliament in 2012 as they launched coordinated attacks in several parts of the capital, including several diplomatic enclaves.

Story continues

- Surging attacks -

The Taliban, toppled from power in the 2001 US invasion of Afghanistan, swiftly claimed responsibility for the latest attack.

"Several mujahideen have entered the parliament building, heavy fighting is on-going," Taliban spokesman Zabihullah Mujahid posted on Twitter.

"The attack happened at a time when the defence minister was being introduced."

Police denied that Taliban fighters had breached the high-security complex.

The surge in insurgent attacks has taken a heavy toll on ordinary Afghans, according to the UN mission in Afghanistan.

Almost 1,000 civilians were killed during the first four months of this year, a sharp jump from the same period last year, it said.

Afghan authorities have repeatedly tried to jumpstart talks with the Taliban in the hope of ending the 13-year conflict, but the militants have set tough conditions, including the withdrawal of all foreign troops in Afghanistan.

NATO's combat mission formally ended in December but a small follow-up foreign force of about 12,500 mainly US troops has stayed on to train and support local security personnel.

President Ashraf Ghani's government has drawn criticism for failing to end growing insurgent attacks, which critics partly blame on political infighting and a lengthy delay in appointing a defence minister.

Ghani last month nominated Mohammad Masoom Stanekzai, a top official in the government body overseeing the country's peace process, for the job.

The post had been left vacant for months due to disagreements between Ghani and his chief executive and former presidential election rival, Abdullah Abdullah, but Stanekzai is expected to be confirmed by Afghanistan's parliament soon.