Media playback is unsupported on your device Media caption Footage showed prisoners, freed by the Taliban, running out of the prison in Kunduz

The Taliban have overrun the northern Afghan city of Kunduz, taking control of most areas and freeing hundreds of prisoners from its jail.

Hundreds of militants stormed the city before dawn, quickly seizing key buildings and advancing on the airport.

The government says it has sent reinforcements to Kunduz and fighting is ongoing.

Kunduz would be the first provincial capital taken by the Taliban since they lost power in 2001's US-led invasion.

The attack came a day before the first anniversary of President Ashraf Ghani's unity government.

Kunduz is strategically important as it acts as a transport hub for the north of the country.

It also has symbolic significance for the Taliban as it was their former northern stronghold before their government was overthrown.

"With the capturing of the police compound and governor's office in Kunduz, the whole province fell to our hands and our fighters are now advancing towards the airport," Taliban spokesman Zabihullah Mujahid said on his Twitter account.

Image copyright AP Image caption Smoke at a police station in Kunduz. The province has seen a number of attacks since April

Image copyright AP Image caption Prisoners freed by the Taliban were seen walking through the streets of Kunduz

Image copyright AFP Image caption The government says its forces in Kunduz are being reinforced

A picture on the same account purportedly showed fighters at a roundabout in the city centre raising the Taliban's white flag.

Later, interior ministry spokesman Sediq Sediqqi confirmed that "most of Kunduz city" was controlled by the Taliban, and said Afghan forces were regrouping at the airport.

A Taliban statement called the operation in Kunduz "an immense conquest" and urged their fighters to protect the local population.

The statement said the government in Kabul "should openly admit its defeat".

Earlier, the government admitted that it had lost control of parts of the city. It said at least 25 militants and two Afghan policemen had been killed and that reinforcements had been dispatched.

Analysis: Dawood Azami, BBC World Service

This attack is one of the most serious security breaches since the start of the Taliban insurgency 14 years ago. But the Taliban's main challenge will now be to hold the city.

Kunduz has a huge strategic significance as it is considered a gateway to Afghanistan's northern provinces and shares a border with Tajikistan, Afghanistan's Central Asian neighbour.

The Taliban already control huge chunks of the province's rural areas, where the majority of the population live. The insurgents have intensified their fighting in the province over the past two years.

They are the dominant militant group in the province, with an estimated 2,000 fighters. But there are also reportedly hundreds of foreign fighters associated with al-Qaeda, so-called Islamic State and the Islamic Movement of Uzbekistan (IMU).

The Afghan security forces are stretched thin as they deal with multiple attacks all over the country.

Bad governance in Kunduz is also a key problem. Incompetence and intimidation by some local officials have alienated many in the province.

Kunduz police spokesman Sayed Sarwar Husaini told the BBC's Mahfouz Zubaide that militants had captured the jail in Kunduz and freed about 500 prisoners, including members of the Taliban.

One of the freed prisoners told the BBC: "It was about 4pm when the Taliban entered the jail and started fighting with police. After a few minutes the police escaped and the Taliban fighters opened all the cells and all the prisoners rushed out."

He said he saw Taliban armed with small and heavy weapons in the streets outside.

Media playback is unsupported on your device Media caption The Afghan government says several militants and two policemen have been killed

Many government officials are said to be trying to flee via the city's heavily fortified airport.

Kunduz province has seen a number of attacks since April, with the Taliban joining forces with other insurgents.

Militant violence has increased across Afghanistan since the departure of most US and Nato forces last year.