Taliban insurgents launched a massive assault on the northern city of Kunduz Monday, seizing a courthouse, a hospital and other government buildings, and freeing hundreds of inmates from a prison, despite a series of battles with government forces.

Interior Ministry spokesman Sediq Sediqqi told The Associated Press that "Kunduz city has collapsed into the hands of the Taliban."

"Security forces in Kunduz were prepared for an attack, but not one of this size, and not one that was coordinated in 10 different locations at the same time," Sediqqi said.

"With capturing of police compound and governor's office in Kunduz, the whole province fell to our hands,” the Taliban's spokesman said Monday on his Twitter account.

The Taliban used social media to claim the "conquest" of Kunduz and reassure residents that the extremist group -- responsible for the vast majority of nearly 5,000 civilian casualties in the first half of this year, according to the United Nations -- came in peace.

More On This...

The fast-moving assault took military and intelligence agencies by surprise as the insurgents descended on the city.  It marked the first time the insurgents have seized a major urban area since the U.S.-led invasion in 2001.

Within 12 hours of launching the offensive around 3 a.m., the militants had reached the main square, tearing down photographs of President Ashraf Ghani and other leaders and raising the white flag of the Taliban movement, residents reported.

Hundreds of Taliban forces also broke into a main Kunduz prison and freed more than 600 prisoners, including 140 Taliban fighters. Many people headed for the airport to flee the city.

Abdul Wadood Wahidi, spokesman for the Kunduz governor, had told the Associated Press that three police officers had been wounded and "more than 20 bodies of Taliban fighters are on the battlefield."

He said reinforcements from neighboring provinces had moved to Kunduz City, with more on the way from other cities, including the capital, Kabul, and Mazar-i-Sharif.

The international medical charity Doctors Without Borders says it has treated more than 100 wounded people in the attacks.

Gen. Murad Ali Murad, the deputy chief of army staff, said Monday's attack involved a large number of Taliban drawn from across the north and included foreign fighters, likely Islamic Movement of Uzbekistan members with an eye on the Central Asian states to Afghanistan's north.

"Strategic areas, including the airport, are controlled by Afghan security forces," he said. "Reinforcements have already arrived and attacks on the insurgent positions will be launched soon," he added, without elaborating.

The fall of the city, which has a population in excess of 300,000, marks a major setback for Afghan government forces, who have struggled to combat the Taliban with limited aid from the U.S. and NATO, which shifted to a training and support role at the end of last year.

"Security forces in Kunduz were prepared for an attack, but not one of this size and not one that was coordinated in 10 different locations at the same time," Sediqqi told the Associated Press earlier Monday.

Taliban spokesman Zabihullah Mujahid claimed responsibility for the attack on his Twitter account, saying the fighters were entering hospitals around the city hunting for wounded government troops. He advised residents to remain indoors.

Mohammad Yusouf Ayubi, the head of the Kunduz provincial council, said city residents were "greatly concerned" about the situation.

The United Nations' Assistance Mission to Afghanistan said all its staff had been evacuated from its Kunduz office.

A senior U.S. defense official, speaking on condition of anonymity in order to discuss an ongoing military operation, said the U.S. military was aware the Taliban had taken control of a hospital and a number of government buildings in the city, and that both sides -- the Taliban and government forces -- had sustained a significant number of casualties.

Early indications were that the Afghan forces were in position to push back the attackers and regain control of the city, although the outcome was still in doubt, said the official, speaking earlier Monday before the government announced the fall of the city.

The strategically located Kunduz, a major producer of grain and other food, is one of Afghanistan's wealthiest cities.

The Taliban previously attacked the city in April, in its first major advance into an urban area, but were pushed back by Afghan security forces. The Taliban is since believed to have regrouped and allied with other insurgents.

The Taliban have a history of brutality toward those they regard as apostates, and have banned girls from school as well as music, movies and other trappings of modern life in areas under their control.

The Associated Press contributed to this report.