Lt. Col. Martin O'Donnell, a spokesman for USA forces in Afghanistan, said American forces and US attack helicopters had assisted Afghan troops in pushing back the Taliban during the night's multiple attacks in Ghazni.
After repulsing the daring nighttime assault, police were conducting house-to-house searches for stragglers and to discover how the Taliban infiltrated so deep into Ghazni city, barely 120 km south of the Afghan capital of Kabul.
Taliban fighters have attacked Ghazni, Afghanistan's eastern provincial capital, leaving dead and wounded before Afghan forces pushed them out of the city, officials said.
An Afghan military helicopter crash landed in the city during the daytime fighting, and four Afghan soldiers on board were injured, one critically, said Mohammad Radmanish, spokesman for the Ministry of Defense.
Hemat, the hospital administrator, said two wounded civilians were brought to the hospital.
The Taliban issued a statement claiming to have captured "most of the government buildings inside the city", and claiming to have killed and wounded 140 security forces.
Taliban spokesman Zabihullah Mujahid claimed parts of the city had been seized and scores of people killed.
United States forces responded with attack helicopters and a drone strike, according to US Forces Afghanistan spokesman Lt. Col. Martin O'Donnell.
The residents said airstrikes also targeted Taliban's positions.
The Taliban are fighting the Western-backed government to restore their version of sharia, or Islamic law, after they were driven out by US -led forces in 2001.
But with Taliban fighters believed to be hiding in residential areas, it was unclear whether the government had full control of the city, with communications badly hit after a number of telecoms installations were destroyed. He said three Taliban had been killed and eight wounded.
The Taliban have stepped up attacks across the country since North Atlantic Treaty Organisation and the United States formally ended their combat mission in 2014, and have seized control of several districts.
The attack on Ghazni comes as the Taliban faces growing pressure to agree to peace talks with the Afghan government to end the 17-year war.
But a spokesman for US Forces in Afghanistan said fighting had "ceased" as of Friday morning. The Taliban have rebuffed offers of negotiations with the government but have held one preliminary round of direct talks with Alice Wells, Washington's top diplomat for South and Central Asia, including Afghanistan.
While he said such a move is probably not imminent, "a few more headlines that show "his generals" are "failing" in Afghanistan could produce some personnel moves, and then a policy shift".
An Islamic State affiliate has carried out dozens of deadly attacks in recent years, mainly targeting security forces and minority Shiites. Associated Press writer Maamoun Youssef in Cairo contributed.