The Taliban militants have largely seized the key Afghan city of Kunduz, storming government compounds and sending panicked residents fleeing.

Fierce fighting raged in Kunduz, in northern Afghanistan, as the Taliban militants freed hundreds of prisoners from the city's main prison, set fire to government buildings and hoisted their flag over the homes of officials.

"The Taliban have taken the city but our forces are still putting up resistance in some areas," AFP quoted Kunduz police spokesman Sayed Sarwar Hussaini as saying.

"They have taken over Spinzar chaman, the main city square. Heavy clashes are ongoing between Taliban and government forces," Hamdullah Danishi, Kunduz deputy governor, said.

Afghan health officials said that at least 15 members of Afghan security forces and 20 Taliban militants have been killed in the fierce fighting.

"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 told AFP.

Afghan residents sit on a truck as they leave their home after a battle with the Taliban in Kunduz Province, Afghanistan September 28, 2015. (Reuters)

At least seven civilians have also lost their lives and about 50 others were injured in the ongoing clashes.

"As fighting rages in Kunduz, all sides must ensure that civilians and civilian objects are protected according to international humanitarian law," Amnesty International said, adding, "Reports that the Taliban have already sent armed fighters into a public provincial hospital are extremely worrying."

Kunduz Province is strategic as it is located on a crossroad that connects key regions of the country. The province has been witnessing fighting between security forces and militants since April.

Analysts say the fall of the provincial capital city to Taliban militants would amount to a major setback for Afghan forces.

This photograph taken on August 1, 2015, shows Afghanistan's militia forces taking position as they remain alert in their conflict against Taliban militants in Qala-e Zal district of Kunduz province. (AFP)

Afghanistan continues to face insecurity 14 years after the US and its allies invaded the country as part of Washington’s so-called war on terror. Although the Taliban were removed from power as a result of the invasion, many areas in the country are still threatened by insecurity.