TAIWARA, Afghanistan — Before the Taliban briefly overran the Taiwara District in late July, the last semblance of resistance came not from the government, but rather from local residents who rallied around their representative in Parliament in what turned out to be a fatal effort for many.

The small Afghan commando unit in Taiwara, in the western part of isolated Ghor Province, had already been routed. Ibrahim Malikzada, the district’s parliamentarian and a hardened anti-Taliban fighter since the 1990s, arrived from Kabul to try to muster a final defense. Mr. Malikzada often travels the 180 miles of mountainous stretch from the provincial capital to the district on a motorcycle, in the dark of the night.

His men were also defeated, on July 23.

“When they were going to their outposts in the evening, from their faces one could tell they would not return,” Mr. Malikzada said. “It was one of the deadliest nights — at every corner, I saw pieces of my men.”

Only days later, Afghan commandos, supported by Afghan and United States airpower, retook Taiwara.

The district’s brief fall and recapture offer a window into how this long war is being fought now: The ungoverned space across the county continues to grow as each side — the government and the militants — rallies resources and wrests control of an individual area for a short time. Neither side, though, seems capable of holding on to territory it gains. The fight seesaws back and forth, with civilians caught in between.