Taliban fighters have seized a major Afghan city for the first time since being ousted from power by the US-led invasion in 2001, storming government compounds and sending panicked residents fleeing.

The insurgents launched a surprise, three-pronged offensive before dawn, and by evening had captured the governor's compound and provincial police headquarters, a Taliban spokesman said.

Fierce fighting raged in the northern city of Kunduz as marauding insurgents freed hundreds of prisoners from the local jail, set government buildings on fire and hoisted their trademark white flag over the homes of officials.

Key points: Taliban take control of a major Afghan city for the first time since US-led invasion

Taliban take control of a major Afghan city for the first time since US-led invasion The moves marks a massive blow to the country's NATO-trained security forces

The moves marks a massive blow to the country's NATO-trained security forces Taliban attacks have increased significantly following the withdrawal of NATO troops

The Taliban's incursion into Kunduz barely nine months after the NATO combat mission ended marks a major psychological blow to the country's Western-trained security forces.

"The Taliban have taken the city but our forces are still putting up resistance in some areas," Kunduz police spokesman Sayed Sarwar Hussaini said, adding that promised reinforcements from Kabul were awaited.

Scores of bodies littered the streets after hours of heavy fighting, Afghan media reported citing local residents, many of whom were making a hasty exit from Kunduz.

Many were fleeing to the city's main airport, which is still in government control, but some complained they were being turned away by security forces.

The city was swarming with Taliban fighters racing police vehicles, who overran the governor's compound and the local police headquarters.

The local headquarters of the National Directorate of Security, the country's main intelligence agency, was set on fire, a security official told AFP on condition of anonymity.

Saad Mukhtar, the head of a 200-bed government hospital, said the Taliban had control of the building and were hunting for wounded Afghan troops.

"Yes, the enemy is in the city and they have taken over the prison and other buildings, but reinforcements will be deployed and the city will be taken back," interior ministry spokesman Sediq Sediqqi said.

He confirmed "most of Kunduz city has fallen to the Taliban", and said Afghan forces were regrouping at the airport.

The new Taliban leader Mullah Akhtar Mansour in a statement congratulated his cadres over the "major victory".

'It looks pretty grim'

"As fighting rages in Kunduz, all sides must ensure that civilians and civilian objects are protected according to international humanitarian law," Amnesty International said in a statement.

"Reports that the Taliban have already sent armed fighters into a public provincial hospital are extremely worrying."

This was the group's third attempt this year to breach the city, which coincides with the first anniversary of president Ashraf Ghani's national unity government in power.

The Taliban's ability to penetrate the city is a major setback for Afghan forces who have been battling the militants without the full support of NATO, which ended its combat mission last December.

The Islamist group has been largely absent from cities since being driven from power by the US and its allies, but has maintained often-brutal rule over swathes of the countryside.

The loss of the half of Kunduz is a major blow to the country's NATO-trained security forces. ( AFP: Najim Rahim )

International Crisis Group senior analyst Graeme Smith said the Kunduz assault was the first major breach of a provincial capital since 2001.

"They are choking the Afghan forces from all sides. It looks pretty grim," he said.

Afghanistan's deputy chief of army staff Murad Ali Murad defended the Afghan security forces' performance, suggesting they withdrew to avoid harming civilians with all-out urban warfare.

"There were enough troops inside Kunduz city, but the insurgents used some route deemed not that sensitive," Mr Murad told a news briefing.

"Our forces arrived there on time, but we had to take extra care not to cause civilian casualties."

Dozens of Afghan special forces were flown to Kunduz airport on a C-130 aircraft and were preparing to launch a counter-attack, according to a senior official in Kabul.

Abdullah Danishy, deputy governor of Kunduz, vowed that Afghan forces would retake the occupied city.

"We have reinforcements coming from other areas and will beat back the Taliban," Mr Danishy said by telephone from Kunduz airport after fleeing his office.

But with most of downtown Kunduz now in Taliban hands and terrified civilians either trying to flee or hiding inside their homes, the insurgents may be tough to dislodge.

"Once they get inside an urban area, your air assets and artillery become much less useful," Mr Smith said.

The Taliban have been waging a bloody insurgency since a US-led invasion booted them from power in late 2001, and have stepped up attacks during a summer offensive launched in late April against the Western-backed government in Kabul.

Afghanistan's thinly spread security forces are also increasingly having to deal with the threat from the self-styled Islamic State group, which is looking to make inroads in the troubled country.

Most NATO troops left by the end of 2014, although a residual force of around 13,000 remains for training and counter-terrorism operations.

Peace overtures by the government of president Ashraf Ghani over summer ended in failure, as civilian casualties soared to a record high in the first half of 2015, according to a UN report.

It said 1,592 civilians were killed, a 6 per cent fall over last year, while the number of injured jumped 4 per cent to 3,329.

AFP/Reuters