KABUL — Taliban forces launched a fierce pre-dawn attack Friday on the eastern Afghan provincial capital of Ghazni, overrunning government buildings amid heavy fighting before being driven out by U.S.-backed Afghan forces, officials said Friday.

But conflicting reports persisted into the evening, with some indicating that the strategic city was still partly in Taliban hands and that the insurgents remained bunkered inside homes and other buildings after hours of battles with Afghan police and attacks by U.S. military helicopters. At least 14 members of government security forces were reported killed.

The assault on Ghazni by several hundred Taliban fighters was the group’s first major urban attack since May, when insurgent forces overran Farah city, the capital of western Farah province, and were driven out in a two-day battle. It was also reminiscent of previous Taliban efforts to capture provincial capitals, including Kunduz in the north. 

The latest attack came despite intensified efforts by Afghan and U.S. officials to encourage the Taliban to begin peace talks.

Lt. Col. Martin O’Donnell, a spokesman for U.S. forces in Afghanistan, said that the insurgents attacked “multiple government centers” in Ghazni but that most were driven back before midmorning. He said Afghan forces were supported by U.S. attack helicopters and a drone strike. Later, though, O’Donnell said U.S. aircraft had returned in a “show of presence” as fighting continued.

A spokesman for President Ashraf Ghani, Shah Hussain Murtazawi, said that by midday, Afghan forces were in full control of the city of more than 250,000. But accounts from some residents and local officials painted a portrait of chaos in Ghazni.

 Zabiullah Mujahid, a Taliban spokesman, said Friday morning on Twitter that hundreds of fighters had entered the city, capturing the police headquarters and a military base. In an emailed statement, he also said the governor’s office, the local offices of the national intelligence services and other official buildings were under attack and that a highway had been cut off to prevent government reinforcements from arriving.

The surrounding province, also named Ghazni, has been infiltrated and attacked by the Taliban for the past several years, and several of the province’s districts are under insurgent control. The city’s location on the main highway between Kabul and Kandahar, Afghanistan’s largest southern city, has always made it a valuable target.

As the Taliban has continued to occupy or influence large areas of the countryside, Afghan and U.S. officials have said they are focusing more on protecting cities, where most civilians live. But the recent attack on Farah and bombings in eastern Jalalabad city by Islamic State militants have raised fears that it will be difficult to protect voters in parliamentary elections scheduled for October. 

The Afghan Defense Ministry said one of its helicopters crashed during the fighting in Ghazni and that another made an emergency landing. Officials denied Taliban claims that its forces shot down government helicopters.

As the day progressed, some local officials reported that Taliban fighters were still roaming parts of the city and that gunfire continued, with frightened residents hiding in their homes. The officials said Taliban forces had seized official buildings, burned police posts and proclaimed victory from mosque loudspeakers.

Afghan officials said 14 members of the security forces were killed and about 20 wounded, but a Taliban spokesman said 140 government personnel were dead. The Taliban often exaggerates such figures. Police officials told the Associated Press that dozens of Taliban fighters were killed in airstrikes.

 Khodad Urfani, a local member of parliament, said the city had been “on the verge of total collapse” before the Taliban attackers were repelled.

Mohammad Rahim Hassanyar, a senator from Ghazni, said the operation to expel Taliban fighters was “very slow.” Speaking by telephone from the city in the early afternoon, he said that no army troops had arrived and that only police were defending the city.

Sharif Hassan contributed to this report.