Afghan forces' Kunduz fightback in pictures
Afghan government forces claim they have recaptured most of Kunduz, but there are reports of sporadic gunfire as the Taliban fight back.
The militants first seized the city early on Monday, pushing security forces back to the airport, from where they had to call on US air strikes to defend their positions, before planning their counter-attack.
Here is how the battle unfolded, in pictures taken by people at the scene.
Although there was fighting on Tuesday and Wednesday, the main operation to recapture the town began as night fell on Wednesday - and is still going on.
Armed Afghan police were also involved in the advance, alongside troops from Kunduz and reinforcements from across Afghanistan.
One of the first signs that the town was falling to government control came as the Afghan flag was pictured flying above the main square again
Posting a picture purportedly from a contact at the scene, Tolo TV presenter Muslim Shirzad credited a young special forces commander named Khalid Amiry with taking down the Taliban flag.
The Taliban raising their own flag there earlier in the week was hugely symbolic - Kunduz was the first provincial capital they had captured since being driven from power by US-led forces in 2001.
The progress of the security forces was seemingly rapid, with several districts quickly appearing to fall to government control.
That was in stark contrast to the situation earlier in the week, when government forces apparently abandoned the town with similar speed.
But government assurances early on Thursday that they were back in control appeared premature, with the Taliban launching their own fightback within hours.
A government spokesman claimed about 200 Taliban fighters had been killed, although the claim could not be immediately verified. Civilians like this man were also caught in the crossfire.
The insurgents used vehicles and weapons seized after their capture of the town, in later battles with government forces. They are also reported to have looted banks during their time in control of the city.
With claims that "thousands" were massed at the airport in advance, troops continued to pour into the city to reinforce those on the front lines.
Remnants of Thursday's battles could be seen around the town.
Parts of Kunduz were on fire. The Taliban were also said to have torched government buildings in preceding days.
After being holed-up in the airport for days, there was relief among government forces that they had regained the initiative even as street battles continued.
A police spokesman in Kunduz claimed the latest fighting was caused by stranded Taliban fighters who have been hiding out in the town. Most residents stayed indoors.
The battles in Kunduz also apparently prompted an anti-Taliban protest in the capital, Kabul, but the repercussions are likely to be far wider, with the Taliban gaining new prestige, and fresh doubts over planned reductions in the number of foreign troops in the country.