KUNDUZ, Afghanistan (Reuters) - Taliban fighters attacked the northern Afghan city of Kunduz on Saturday, setting off hours of gunbattles that raged even as U.S. negotiators were trying to seal an accord with the insurgents aimed at ending the war.

Afghan security personnel fires towards Taliban positions on the street in Kunduz, Afghanistan August 31, 2019 in this still image taken from a video obtained by REUTERS. Afghan Interior Ministry/ReutersTV via REUTERS

Scores of people were killed during fighting which began in the early hours and continued throughout the day as government forces, backed by air strikes, fought to regain control of the city, where electricity and water supplies were cut and telephone services badly interrupted.

Residents who could be contacted by telephone said they could hear the sound of gunfire across the city, a key strategic post close to Afghanistan’s northern border which the insurgents have twice overrun since 2015.

“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.

The fighting came as U.S. and Taliban officials in Doha appeared to getting closer to an agreement that would see the withdrawal of thousands of U.S. troops in exchange for security guarantees that militant groups such as al Qaeda could not use Afghanistan as a base for attacks on the United States and its allies.

Underlining the gravity of the fighting, the Afghan defense and interior ministers and General Scott Miller, the senior U.S. commander in Afghanistan, flew to the city to help oversee its defense as reinforcements were rushed in.

In the early evening, a Taliban suicide bomber struck one of the city’s main squares, killing at least 10 soldiers and civilians, officials said.

Government officials in Kunduz and Kabul said Taliban were seeking shelter inside homes and some had entered the main hospital in the city. The Interior Ministry said at least 36 insurgents were killed in ground and air operations in three areas of Kunduz city and clearance operations were under way.

At least three civilians were killed in the battles and 41 wounded were taken to hospitals, said Ehsanullah Fazli, head of the public health department in Kunduz city but a final casualty total was not available.

Slideshow ( 5 images )

“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 government spokesman.

TALKS CONTINUE

As the fighting went on, Zalmay Khalilzad, the Afghan-born U.S. diplomat leading negotiations for Washington, tweeted that he had told his Taliban counterparts “that violence like this must stop”.

“Ultimately, war will only end when all sides agree it must end,” he said. Negotiations continued on Saturday but there was no indication of when an agreement might be reached.

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.

However the operation in Kunduz appeared to underline the Taliban’s determination to secure as strong a position as possible on the battlefield ahead of negotiations with the Afghan government over the future of 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. Several thousand U.S. forces also carry out counter-terrorism operations.

U.S. President Donald Trump said on Friday the United States had had good negotiations going on with the Taliban but had not yet reached a deal with them on U.S. troops withdrawing from Afghanistan.

Sources in the Taliban said Trump’s statement that the United States would continue to maintain a force in Afghanistan even after a deal was reached was unacceptable to them as they were demanding a complete pull-out of foreign forces.

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

More than 1,500 civilians were killed or injured last month, according to the United Nations.

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.