“Nine insurgents have been killed, one other is injured and another one is still holding up against our forces,” the ministry said.
“Unfortunately during the battle, 37 innocent Afghans were killed and 35 others injured,” it added, without specifying how many of them were civilians.
Local residents said they had heard soldiers pleading with the insurgents to free women and children, who were screaming during the fighting that erupted shortly after sundown in the southern city on Tuesday.
One security official told AFP that the assailants held some civilians as “human shields”, which had complicated their clearance operation.
The brazen raid on the sprawling compound, which also houses a joint NATO-Afghan base, is the second major Taliban assault in as many days in the city recognised as the birthplace of the Taliban.
The militants had managed to breach the first gate of the high-security complex and took up position in an old school building, engaging security forces in pitched firefights.
The Taliban claimed responsibility for the attack, with spokesman Zabihullah Mujahid saying on Twitter that “150 Afghan and foreign soldiers” had been killed in the fierce fighting.
The insurgents are regularly known to exaggerate battlefield claims.
The raid coincides with Afghan President Ashraf Ghani’s high-profile visit to Islamabad on Wednesday for the Heart of Asia conference aimed at promoting regional ties.
Ghani’s willingness to visit longtime nemesis Pakistan, which wields considerable influence over the Taliban, has signalled a renewed push to mend badly frayed cross-border ties which in turn could help jump-start peace talks with the insurgents.
The raid also comes after days of fevered speculation about the fate of Taliban leader Mullah Akhtar Mansour following reports that he was critically wounded in a firefight with his own commanders in Pakistan.