KHWAJA UMARI, Afghanistan — The battle for control of an Afghan district is often fierce, involving car bombs, airstrikes and raids that destroy government buildings and leave a trail of bodies.

But the Afghan military’s routing of the Taliban two weeks ago from Khwaja Umari, a district about 10 miles from Ghazni City, capped a rare period of relatively good news for a military demoralized by years of high casualties and territorial loss.

More proactive security forces, borne of a generational shift to younger leaders, have been credited with denying the Taliban any major new gains at a crucial time of peace negotiations. The forces have ruthlessly used commandos and airstrikes to bleed the insurgents, waging what has been a more flexible and adaptive counterinsurgency compared to the older ways, when the forces remained less mobile and largely defensive.