At an Afghan army base on the outskirts of this besieged city, a father was anxiously pacing as he waited to reclaim the body of his son, who was killed this week while battling the Taliban.

Other civilians were there, too — residents who had escaped the Taliban’s brutal advance into Kunduz on Monday. Afghan army generals, as well as U.S. and German troops, moved around the base as they tried to figure out how to drive the militant group from this northeastern city for good.

Despite 14 years of war and tens of billions of dollars in international aid, for much of the day it seemed that nothing had changed on this base on the front line of the Afghan military’s struggle to keep a frightened nation safe.

On Thursday morning, three days after the Taliban overran Afghanistan’s sixth-largest city, government leaders announced that they had largely ejected the militants from the center of Kunduz. But new fighting later erupted throughout the city, signaling to Afghan leaders and residents alike that the war that has devastated the country will not end any time soon, and could worsen in the coming years.

“No one can predict the duration of war,” said Gen. Murad Ali Murad, deputy chief of staff of the Afghan army, who is commanding the Kunduz operation.

At an evening news conference in Kabul, President Ashraf Ghani also tried to prepare the public for more hardship after the Taliban’s advances this week. Although Ghani stressed that Afghan special forces made serious gains in Kunduz on Thursday, he noted that conflict continued in 10 to 13 of Afghanistan’s 34 provinces.

“The war is still going on,” said Ghani, who had hoped to persuade Taliban leaders to take part in peace talks.

Amid growing public alarm, he urged residents to remain optimistic. “Panicking and fear, and becoming perplexed . . . and apprehensive during wartime is helping the enemy,” Ghani said.

But here in Kunduz, the grim reality of what is at stake was increasingly apparent.

Amnesty International said that as part of its Kunduz campaign, the Taliban has carried out mass murder, gang rapes and house-to-house searches for civilians suspected of working for government agencies or international aid organizations.

Female relatives and children of Afghan soldiers and police officers who fled Kunduz when the Taliban stormed in have been raped and, in some cases, killed, local activists told Amnesty International.

The group said the Taliban killed a woman who worked as a midwife in a maternity ward because she had provided reproductive services.

With journalists here largely confined to the army base, it is difficult to verify the claims.

But interviews with residents suggested that the Taliban’s assault on Kunduz has been ruthless.

“The Taliban have burned government offices, broken into the houses of people and robbed the shops,” said Atta Mohammad Rasoli, who fled his home to seek shelter at the base. “Kunduz city has collapsed from inside.”

Afghan security forces now confront a big challenge: how to drive the remaining Taliban fighters from the city — and from Afghanistan.

Although northeastern Afghanistan was relatively secure for much of the war, the Taliban has steadily gained ground this year. In his news conference, Ghani said Islamist militants from Pakistan, Russia and China are mingling with local Taliban sympathizers, compounding the problem.

Afghan officials reported Thursday that more than 160 Taliban fighters were killed Wednesday night during the army counteroffensive, which was backed by U.S. airstrikes. In one neighborhood on the outskirts of Kunduz, the charred corpses of three Taliban fighters lay on a road next to a stolen Humvee, which had apparently been targeted in an airstrike.

Afghan military officials have not said how many soldiers have died in the fighting.

Khan Zari, who is in his 60s, showed up at the base on Thursday looking for the body of his son, a soldier killed this week.

“My son was recently married, and he only passed two nights with his wife when he headed to Kunduz,” said Zari, who lives in the eastern province of Nangahar.

With Taliban fighters still holed up in houses in parts of Kunduz, residents said the city alternated between extended periods of calm and intense street battles on Thursday.

Shortly after dawn, after Afghan forces pressed into the center of the city, a soldier removed a Taliban flag hanging in the town square. Later in the day, however, Taliban fighters retook the square and again hoisted their flag, according to a witness account published in the Stars and Stripes newspaper.

On Wednesday, the U.S.-led coalition in Kabul confirmed that American Special Operations troops and NATO military advisers had arrived in Kunduz to assist in the counteroffensive. The U.S. troops were dispatched to Kunduz to “train, advise and assist” Afghan forces, but they are empowered to defend themselves if threatened.

About 9,800 U.S. troops remain in Afghanistan, but coalition officials have declined to specify how many have been assigned to Kunduz. On Thursday, half a dozen U.S. troops in combat gear were seen in a Toyota pickup cruising through the Afghan base.

According to an Interior Ministry official, U.S. military commanders in Kabul are increasingly involved in trying to bolster communication and coordination between Afghan army and police units. Many analysts say that basic military command-and-control procedures broke down Monday as the Taliban advanced.

The official, speaking on the condition of anonymity to discuss the matter freely, added that Afghan forces at times this week appeared to be close to the “breaking point” because of declining morale. In frank discussions with coalition commanders, Afghan generals have pleaded for more help from the international community.

“They are saying, ‘Please give us more weapons, more ammunition, tanks, and then we can fight the Taliban,’ ” the official said.

Coalition commanders are responding, the official said, with tough talk.

“The Americans are saying, ‘It’s war, but it’s an Afghan war, and you have to face it, tolerate it, so you can survive and save the country,’ ” the official said.

The fighting in Kunduz, Afghan security officials are apparently being told, “is practice for you guys.”

Craig reported from Kabul. Sayed Salahuddin in Kabul and Daniela Deane in London contributed to this report.

Read more:

Afghans who once watched war from afar are forced to flee as front lines shift

Taliban has a major northern Afghan city within its grasp for the first time since 2001

Today’s coverage from Post correspondents around the world