An ominous orange glow lit up the sky for miles around. It was after midnight on Aug. 11, and the city of Ghazni, less than 100 miles from Kabul, was on fire. Approaching the outskirts of town in a convoy of heavily armored 22-ton vehicles, the team of Green Berets from Operational Detachment Alpha (ODA) Team 1333 took it as the first sign that it wasn’t going to be an easy night.

The group was one of three U.S. Army Special Forces–led units converging on Ghazni to save it from the Taliban, which had laid siege to the city over the previous 24 hours in a surprise attack. And the closer the Green Berets got, the worse it looked. Approaching the city, ODA 1333 had to muscle their massive vehicles around bomb craters and abandoned big-rig trucks that the Islamist insurgents had set up as roadblocks.

The dismal obstacle course wasn’t just proof that the insurgents had the upper hand over the 1,500 Afghan police and soldiers based in the city, even though those forces were flush with sophisticated American-supplied weaponry. The team soon discovered the wreckage-strewn approach to the city had become a shooting gallery for hidden Taliban.

Rocket-propelled grenades and machine-gun fire came screaming in from a tree line to the east—small bursts at first, then all at once. Streaks of heavy fire glowed green in the commandos’ night-vision goggles as two- and three-man Taliban teams shot rockets at the Special Forces before vanishing into nearby scrubland. The U.S. forces returned fire with rapid bursts from the .50-caliber machine guns perched atop the vehicles. At one point, one of the men shouted, “Where the f-ck are [the airstrikes]?” Almost on cue, a lumbering AC-130 gun ship circling above began showering 105-mm cannon fire on Taliban positions below. Apache attack helicopters, A-10 attack planes, F-16 fighter jets and MQ-9 Reaper drones also delivered airstrikes. The road into the city “was just a sh-t show,” one U.S. soldier tells TIME.

Back in Washington, the war in Afghanistan often seems like an afterthought. According to the Pentagon, combat missions officially ended in 2014, U.S. forces serve only as “advisers,” and peace may be at hand. An unprecedented three-day June cease-fire was followed by secret U.S.-Taliban talks in Qatar in July. “We’re seeing the strategy is fundamentally working and advancing us toward reconciliation, even though it may not be playing out the way that we anticipated,” General John Nicholson, the top U.S. commander in Afghanistan, said on Aug. 22.

A Green Beret, left, and a Special Tactics airman prepare to move toward Ghazni from a makeshift outpost on Aug. 16. Emanuele Satolli for TIME

A wall damaged by a Taliban mortar at a small makeshift outpost in Ghazni; two Afghan soldiers were injured. Emanuele Satolli for TIME

An Afghan soldier talks on a radio atop a Ghazni building. Emanuele Satolli for TIME

But in August, America’s 17-year enemy in Afghanistan, the Taliban, launched a coordinated set of assaults around the country ahead of the Muslim holiday of Eid al-Adha. With echoes of the Tet offensive carried out by the Viet Cong during the Vietnamese New Year in 1968, the Taliban attack targeted vulnerable outposts peppered across seven provinces and claimed the lives of scores of Afghan forces.

The assault on Ghazni, which engulfed nearly all of the city’s 19 districts, was the most orchestrated operation of this nationwide onslaught. And the Taliban’s surprising effectiveness—capturing districts, nearly toppling a provincial capital and briefly ­cutting off the main north-south highway just 60 miles from the capital—raises troubling questions about the state of the war. The battle was a major test of the Trump Administration’s long-term military strategy, which hinges on defending population centers while ceding much of the remote countryside to the Taliban. It proved that U.S. forces still routinely rush to save Afghan forces struggling to contain a resurgent Taliban. That hard truth suggests the plan to train, advise and assist Afghans so they may one day defend themselves masks the costs the U.S. is still paying nearly two decades into the war, and a year after President Trump announced a new strategy to defeat the enemy. As Ghazni shows, the “assist” part is often difficult to distinguish from a traditional American combat mission.

Nine Americans were evacuated from the battlefield by helicopter because of injuries incurred by the Taliban’s multiday barrage of roadside bombs, mortar shells and rockets. At least two soldiers received Purple Hearts after suffering serious wounds. Seven out of 10 armored vehicles in ODA 1333’s convoy were lost to battle damage. The Special Forces team considered themselves lucky: a shoulder-fired rocket had a near miss with a medevac helicopter retrieving an injured soldier.

The carnage in this city of 150,000 shows how devastating the war remains for Afghans. An average of seven Afghan adults and two children were killed every day in the first six months of this year, according to the latest United Nations data, with another 19 civilians injured each day. The figures show 2018 is on track to be the deadliest year of the war. A generation of American military officers who arrived here after the Sept. 11, 2001, attacks as fresh-faced lieutenants or majors have lived through the ferocious fighting. Some are now multiple-­tour colonels or generals, with children who have inherited the burden of waging America’s longest war. Most of the soldiers—American and Afghan—­who battled to take back Ghazni were in grade school on Sept. 11 and unable to foresee the countless ways the attacks would shape their lives.

This account of the multiday siege of Ghazni, described to TIME in on-the-ground interviews with dozens of U.S. and Afghan soldiers, commanders and citizens, offers a rare glimpse into the ongoing American military effort in Afghanistan. The extent of the destruction has not been previously reported. The Pentagon doesn’t make the information publicly available, and TIME witnessed it only after gaining approval for an embedded deployment in Afghanistan after months of trying, long before the August offensive began.

Nakibullah Salwary, 35, who was injured during the Taliban assault on Ghazni, sits on a hospital bed on Aug. 16. Emanuele Satolli for TIME

The battle for Ghazni didn’t come out of nowhere. The Taliban sensed an opportunity in the widening chaos created by years of war. For several months, five U.S. Special Forces teams, working with some 150 Afghan commandos, had left the area to fight a different threat: a growing Islamic State affiliate known as ISIS-Khorasan, or ISIS-K. An offshoot of the Syria-based terrorist group, it formed in Afghanistan in 2015 and has terrorized towns in eastern Nangarhar province through public executions, assaults on government buildings and suicide attacks.

The effort to repel ISIS-K was one of the largest joint operations ever conducted between U.S. and Afghan special forces. By August 2018, ISIS-K had lost nearly 200 fighters and most its territory. The joint mission did not go unnoticed. Over the summer, the U.S. military received intelligence that the Taliban was aware the Americans and Afghan commandos based around Ghazni were gone, Special Forces sources tell TIME.

The Taliban couldn’t believe their good fortune. Moving weapons and fighters into Ghazni isn’t a difficult task. There are many ways to smuggle materiel into the city, through ancient trading lines or unassuming vehicles that blend in with traffic. Some local officials believe security personnel guarding Ghazni’s perimeter granted the Taliban free entry.

Despite the intelligence tip, the Taliban’s initial attacks on Aug. 10 caught Washington and Kabul flat-footed. An estimated 1,000 Taliban fighters stormed the city and surrounding districts. The insurgents attacked government buildings, assaulted the central prison, destroyed a telecommunications tower and set fire to a local television station. Afghan local police and military officials temporarily lost control of several areas of the city.

U.S. Special Operations Command headquarters scrambled to respond, deploying three 12-man Green Beret teams from 1st Special Forces Group along with their Afghan partnered force from the 2nd Commando Kandak, and conventional U.S. infantry soldiers from 1st Stryker Brigade Combat Team, 4th Infantry Division.

For the men of ODA 1333 and their detachment of around 100 U.S. soldiers and Afghan commandos, the orders sounded straightforward: help secure two Afghan helicopters downed by the Taliban near Ghazni. They knew they would have to take the long way around, because the Taliban had buried so many land mines along the direct road leading into Ghazni that it was impassable. What was usually a 60-mile trip westward from Paktia province would instead cover 160 miles of terrain. The troops loaded up their weapons and clambered aboard hulking RG-33 and M-ATV armored vehicles, which rumbled into the night toward Highway 1, an ancient 300-mile two-lane road that serves as the main artery linking the seat of government in Kabul to Kandahar.

The Taliban knew the Americans were coming and where they were coming from—there was only one way in. So the militants lay in wait, armed with rocket-propelled grenades, mortars and AK-47s.

The soldiers of ODA 1333 would never reach the downed helicopters. Instead, they spent the next five days fighting hundreds of Taliban fighters in an endless series of running battles that debilitated vehicles and maimed members of their unit. “I’ve never seen that many [rocket-propelled grenades] in my career,” says the team’s sergeant, who, like others, spoke to TIME on the condition of anonymity.

In the face of recurring attacks, ODA 1333 and their attached units weren’t able to breach the city until some 17 hours later. The soldiers moved to a small makeshift outpost on Ghazni’s outskirts, where U.S. Special Forces teams had been based before the 2014 troop drawdown. Even there, they could find no refuge. Within 25 minutes of arriving, a mortar round arched over the perimeter and crashed through the back wall of a plywood structure where two Afghan soldiers were bedding down. The percussive thump of mortar fire shook the ground under the men, followed by the crack of gunfire over their heads, ODA 1333’s intelligence chief recalls. As the Americans and Afghans scrambled for protective cover, Apache helicopters wheeled low outside the base, hunting for the fighters responsible, blanketing the perimeter with gunfire and briefly quieting the attacks.

Stenciled doors of two armored vehicles at a military outpost in Ghazni. Emanuele Satolli for TIME

Special Forces soldiers sleep at a military outpost. Emanuele Satolli for TIME

A Special Forces soldier reads a military manual at the outpost on Aug. 15. Emanuele Satolli for TIME

By that time, the sun was out and the fighting had died down enough to set up camp. When the Afghan troops were finally able to shed their combat gear, it was clear many of them had been toddlers when the war began in 2001. Some infantry soldiers still had baby faces, unlike the bearded, tattooed Special Forces team members. All were motivated to get back into the fight. The Taliban had not seized control of a provincial capital in Afghanistan since 2015. It wasn’t going to happen again on their watch.

On Aug. 12, ODA 1333 prepared to mount a counter­attack. U.S. Special Forces Team ODA 1212, which arrived overnight, would also push inside the city. The teams would be further aided by 60 additional Afghan commandos and aerial footage from MQ-9 Reaper drones. The goal was to secure the government facilities, police headquarters, prison and district center under attack. The operational plan was coordinated with Afghan forces, which had incurred more than 100 casualties from two straight days of fighting. As they left the outpost and headed into the city, team members could see decomposing corpses in front of burned-out buildings.

For those who lived in Ghazni, the scene was apocalyptic. Gunfire rattled through the air, rockets hissed and airstrikes crashed in the distance. Sami Ahmadi, a 24-year-old English student at Ghazni University, gathered his family and huddled inside his basement for shelter. “We were terrified,” he recalls. “Police were killed, their bodies lying in the road.”

As forces pushed farther into the city, waves of citizens emerged, carrying what they could in their arms to flee the fighting. They were migrating north on foot to seek safety in nearby towns, or even onto Kabul. Behind them, small teams of Taliban were laced through Ghazni’s narrow, serpentine streets.

The insurgents had stormed the prison on the southeastern edge of the city to free captured fighters, but that attempt was ultimately thwarted. Their effort to breach the provincial government building was quashed as well. But the Taliban put up a tough fight in the streets. At one point, as ODA 1333’s convoy inched forward, three Taliban emerged from an alleyway and fired a rocket that slammed into one vehicle’s machine-gunner turret, injuring the Air Force pararescue jumper manning the position. Bits of metal and debris flew into the vehicle. The air was thick and acrid. “There was so much smoke and dust,” says Tamim Ahmed, the team’s Afghan interpreter. “I couldn’t see straight for a couple minutes.”

The vehicle’s other gunner turned his weapon on the Taliban fighters, who were dumbfounded they didn’t kill everyone inside the truck. With a burst of fire, the gunner took out all three insurgents. But the pararescue jumper was severely wounded. A young soldier in another vehicle was also hit with shrapnel that would ultimately claim an eye. Neither man has been publicly named, but both later received Purple Heart awards, according to U.S. military officers in Afghanistan. (Despite their perilous mission, the U.S. military officially labels these soldiers as “advisers.”) When a rescue helicopter arrived to evacuate the wounded, a rocket came within 150 feet of hitting it.

It was clear from the nonstop attacks that U.S. forces would have to stay inside Ghazni Provincial Center, a local government headquarters building, to ensure it wouldn’t be overtaken. ODA 1212 split off from 1333 and established a headquarters there with Afghan forces. The soldiers stayed away from open windows and tried to remain hidden on the roof from snipers positioned just outside the facility’s fortified gates, waiting for a clean shot.

Over the following two days, the Taliban switched its focus to Ghazni’s less-defended surrounding areas. Afghan commando and Ktah Khas counter­terrorism teams went house to house, clearing neighborhoods of Taliban fighters. It was the audacity of the Taliban’s tactics in Ghazni that stuck out to U.S. soldiers. ODA 1333 and other teams had been attacked in Ghazni before, but typically in hit-and-runs—Taliban fighters would hang a mortar round or take a pot shot at their enemies, then melt in with the local population. During this siege of Ghazni, the insurgents walked the streets in broad daylight, firing on American armored vehicles, knowing U.S. warplanes were hunting them overhead. “From a military standpoint, it’s not very smart,” the Special Forces team sergeant says. “Because they attack and they usually die. But if they get off what they need to get off, I guess they feel like they win.”

The Taliban seemed to have a limitless supply of rockets, sometimes firing 20 or 30 at a time. One after another, U.S. vehicles were knocked out of the fight. When that happened, another unit would arrive to hook up a tow rope and drag the vehicle out of the kill zone, all while exposing themselves to enemy fire. The Taliban had all that firepower inside the city, and Afghan and U.S. forces had to deal with it.

But in addition to armor, advanced weaponry and superior training, the U.S. had another major advantage: air dominance. The military said it dropped 73 bombs and missiles in the Ghazni operation. By Aug. 15, a third Special Forces team and additional units had arrived in Ghazni. Thanks to the airstrikes, the Taliban began falling back. The U.S. military said 226 Taliban were killed during the operations.

Typically, both sides declared victory. Even as the fighting drove them from the city, the Taliban bragged that it had sent a clear message to President Donald Trump that “the conquest of this city signifies the failure of yet the latest American strategy,” according to a released statement. “The experience of Ghazni has proven that no defensive belts of cities can withstand the offensive prowess of the Mujahideen.” In truth, the strategic value of the Ghazni attack seems to have been the tweets, headlines and video footage that rippled across social-­media feeds, showing armed Taliban brazenly roaming free inside the city center. The message was clear: the Taliban remains a fierce enemy who can strike whenever they choose, regardless of peace talks and hopes of reconciliation.

From the U.S. and Afghan militaries’ view, the battle was a success. Afghan soldiers, though heavily reliant on American Special Forces and airpower to turn the tide, stood, fought and routed the enemy within five days. The Afghan commandos garnered respect for their performance. “They stepped up, no doubt,” says Noah Olson, a 20-year-old Army Specialist. “They want to get this over with as much as we do.” U.S. military brass declared the onslaught a misfire from a fading enemy. “Tactically, operationally and strategically, the Taliban achieved nothing with this failed attack except another eye-catching, but inconsequential headline,” said U.S. Army Lieut. Colonel Martin O’Donnell, spokesman for the U.S.-led international military coalition in Kabul.

On Aug. 16, residents of Ghazni view buildings damaged during a recent Taliban siege. Emanuele Satolli for TIME

Nassarath Kadri, 27, inside his damaged shop in Ghazni on Aug. 16. Emanuele Satolli for TIME

Two Afghan boys paint a blast wall in Ghazni; the Taliban attacked the city ahead of the Muslim holiday Eid al-Adha. Emanuele Satolli for TIME

Like most narratives emanating from Afghanistan, the truth lies somewhere in between. Looking at the damage inside Ghazni, it was hard for anyone to declare a true victory. Carcasses of burnt-out buildings smoldered in the sun. Stores that bristled with goods for the upcoming holiday became husks of blackened, twisted metal. “At a time like this, your neighbors are like brothers,” says Said Mohammed, 63, whose restaurant managed to emerge unscathed. “We grieve for them.”

The bloodshed was also apparent. At Ghazni Provincial Hospital, rooms were filled with patients of all ages who had suffered wounds in the onslaught. Dr. Abdul Basir Ramaki, the hospital’s medical director, said that the dead tallied 150, with 265 more injured, as of Aug. 16. “Many were women and children,” he says. “All Afghan people are tired of this violence.” (A U.N. report quoted “unverifiable numbers” that put the civilian death toll at more than 150.)

Guma Khan, an elderly man with a long white beard, lay on his back in a hospital bed, recovering from a bullet wound to his left leg. “I was just walking down the street,” he says. “How am I supposed to go on living here?”

Brigadier General Dadan Lawang, the commander of the Afghan National Army’s 203rd Corps, told TIME that 112 Afghan military and police were killed, and 56 were wounded. He said his team was reviewing its security posture to guard against future attacks. “We need to ensure this never happens again,” he says.

But the aftermath of the battle shows why that vow is unlikely to hold. On Aug. 17, Afghan President Ashraf Ghani arrived at the joint military headquarters in Ghazni Provincial Center. He blamed Pakistan for the Taliban attack, saying that many of the fighters were streaming back across Pakistan’s borders. ­Islamabad has long been blamed for giving the Afghan Taliban safe harbor, and Ghazni lies near tribal regions in Pakistan’s Khyber Pakhtunkhwa and Baloch­istan provinces.

Ghani claimed Pakistan’s military chief, General Qamar Javed Bajwa, had assured him over the phone that cross-border insurgent activity would not be allowed after the July 25 elections in Pakistan. “I need answers now,” Ghani said. “From where did they come from and why are they receiving treatment in your hospitals?” (Pakistan denied any involvement.)

The initial success of the Taliban assault was aided by the apparent lack of coordination between Afghan security forces. The local police were running low on supplies and ammunition and had difficulty communicating, according to Afghan officers. In addition, two American soldiers told TIME that they heard that the Afghan National Army had accidentally fired on their own units, as well as American convoys. When asked about the eyewitness accounts, the U.S. military command in Afghanistan said those reports remained unconfirmed. If true, the lack of readiness suggests Afghan forces may need “assists” from the U.S. Special Forces for some time to come.

When the fighting finally died down, the U.S. soldiers were looking forward to returning to their bases in the region, where they had running water, toilets and food that wasn’t prepared in a box. More than a week’s worth of combat made the prospect of returning to the amenities of a long-­established headquarters particularly appealing. Almost all the men had endured close calls and considered themselves fortunate to have made it out alive. “Our luck’s running out,” one soldier said, half-jokingly. “I still have five months here. My number’s going to be called eventually.”

Write to W.J. Hennigan at william.hennigan@time.com.