Taliban forces attacked the northern Afghan city of Kunduz (Representational image)

Taliban forces attacked the northern Afghan city of Kunduz on Saturday, Afghan and Taliban officials said, even as the United States and the hardline Islamist group seem close to finalizing a deal for the withdrawal of American troops.

Heavy fighting has been going on in Kunduz city after the Taliban fighters mounted attacks from several directions on Friday night, forcing the Afghan forces to retaliate and secure reinforcement to prevent the insurgents from gaining control over parts of the city.

Electricity and most telephone services were cut and residents were sheltering in their houses.

"The city is completely empty, shops are locked, people aren't moving and light and heavy weapons can be heard in several parts of the city," said local resident Khaluddin, who like many Afghans goes by a single name.

Government officials in Kunduz and Kabul said the Taliban were seeking shelter inside homes, making it impossible for Afghan and U.S. forces to conduct air strikes, and some of the fighters had entered the main hospital in the city.

The interior ministry said at least 34 Taliban insurgents were killed in ground and air operations in three areas of Kunduz city and clearance operations were underway.

"Security forces are repelling the Taliban attack on some parts of Kunduz city. Their top priority is to protect the civilians," said Sediq Sediqqi, a spokesman for the Afghan President Ashraf Ghani.

"As always the Taliban have taken positions in civilian areas," he said in a tweet.

Taliban spokesman Zabihullah Mujahid confirmed the attack on Kunduz city. Over the past two years, the insurgent group has thrice managed to seize large parts of areas surrounding the city before being driven off after days of fighting with the Afghan forces and air strikes conducted by the U.S. forces.

The fighting in Kunduz, a strategic northern city that the Taliban came close to capturing twice in recent years, came as expectations have grown that U.S. and Taliban negotiators in Doha were close to securing an agreement that would see a timetable for the withdrawal of thousands of U.S. troops.

Zalmay Khalilzad, the Afghan-born U.S. diplomat leading the talks for Washington, is expected in Kabul in the coming days to outline the terms of a settlement to the Afghan president ahead of meetings with NATO partners.

A U.S.-Taliban accord would not in itself end the fighting in Afghanistan but it would open the way for talks between the Taliban and the government in Kabul for a wider peace agreement.

U.S. President Donald Trump said on Friday the United States had good negotiations going on with the Taliban but had not yet reached a deal with the Islamist group on U.S. troop withdrawal from Afghanistan.

Sources in the Taliban said Trump's statement that the United States will continue to maintain a force in Afghanistan even after a deal was reached was unacceptable to them as they demand a complete pull-out of foreign forces from the country.

About 20,000 foreign troops, most of them American, are now in Afghanistan as part of a U.S.-led NATO mission to train, assist and advise Afghan forces. Some U.S. forces carry out counter-terrorism operations.

Despite peace talks, fighting between the Taliban and Afghan forces, who are backed by U.S. air power, has not subsided.

An American service member was killed in combat operations in Afghanistan on Thursday, the U.S. military said, the third to be killed here in the past eight days.