AP PHOTOS: US troops on front lines of America's longest war

During the course of America’s longest war, more than 800,000 members of the U.S. military served in Afghanistan, a multigenerational fight against a tenacious insurgency.

For the troops on the front lines, sometimes it meant holding a remote outpost as mortars, rockets or gunfire hit almost daily. It meant patrols through orchards hunting for hidden Taliban, down roads laced with explosive devices. They took missions into villages, trying to build support among residents. Raids targeting militant commanders turned into gun battles.

With the surge that began in 2009, troops wrested back territory from the Taliban in the group’s southern strongholds in Helmand and Kandahar provinces, only for the insurgents to recapture it years later when the surge receded. In strategic valleys, like Korengal in the high mountains by the Pakistani border or Aurangdal in the south protecting the approaches to Kandahar, cycles of troops over the years dug in, fought and tried to expand their control.

The Americans' combat role was declared over nearly seven years ago, but troops continued in training Afghan forces and in hunting down terrorist groups. On Friday, the last troops left Bagram Airfield, north of Kabul, their main base throughout the conflict, handing it over to the Afghan military, a signal that the full withdrawal from the country was nearly completed.

Over the course of nearly 20 years, more than 2,400 American servicemembers were killed and more than 20,000 were wounded.