The attack on Ghazni city began overnight on Friday.
Within hours, the Taliban claimed to have much of the capital under their control.
Defence Ministry spokesman Mohammad Radmanish later said the army supported police and the city was now under control of government forces.
After the assault, police conducted house-to-house searches to discover how the Taliban managed to infiltrate deep into the city, which is 120km south of Kabul.
At least 14 security forces were killed and 20 wounded in the battle, said Baz Mohammad Hemat, administrator of the Ghazni city hospital.
Dead bodies of Taliban fighters remained on the street after the exchange, provincial police chief Farid Ahmad Mashal told the Associated Press news agency.
He said the bodies of 39 Taliban soldiers were recovered beneath a bridge in the southern edge of the city.
Air strikes called in to quash the offensive also killed dozens of Taliban, he said.
The attack on the strategic city, which straddles the main route between the capital Kabul and southern Afghanistan, demonstrated the Taliban’s strength amid increased speculation about a possible ceasefire during the Eid holiday this month.
All shops in the city were closed due to the fighting. The road from Kabul to Afghanistan’s southern provinces was also closed because it runs through Ghazni.
The attack followed a similar assault on Farah in May, when fighters came close to overrunning the city in western Afghanistan.