Scouts are leaving for the mountains in Jalalabad, Afghanistan, during the Soviet Afghan War, 1986-1989. (Photo by Viktor Khabarov)

Mother and son reunion in Termez, Uzbekistan. (Photo by Viktor Khabarov)

They say history is written by the victors. Russia was defeated in its nine-year-long invasion of Afghanistan, and it finished its ignominious withdrawal 30 years ago this Friday. Yet Russia’s president, Vladimir Putin, insists that his country’s legacy of strength is uninterrupted and unblemished. Which is why Moscow is marking the anniversary of its defeat with the pomp and ceremony of a triumph. The parliament is expected to pass a resolution justifying the Soviet invasion in 1979, overturning the Kremlin’s previous condemnation of the war as a “political mistake,” and lavish commemorations will be held across the country.

This is a tremendous feat of national fantasy. During Russia’s nine-year war in Afghanistan, at least 1 million Afghans and 15,000 Soviet soldiers died. Afghanistan was devastated, its agriculture was ravaged, and one-third of its people fled and became refugees. The Soviet invasion is widely seen as the beginning of what Afghans now call their “forty-year war.” Soviet citizens at the time were bewildered and privately furious about the officially imposed silence and mounting casualty toll — all while the state was collapsing.

Viktor Khabarov, now 67, was then a major in the Soviet military, working among the troops as a photographer. While the Kremlin made lofty decisions about the conflict from Moscow, he saw it close up, on the ground. From 1986 to 1989, he hopped in and out of Afghanistan on assignment for Red Star, the Soviet (and now Russian) military newspaper.

Photographing war today is not what it was then. There were few rules and restrictions on Soviet photographers in Afghanistan, and Khabarov relished his independence. “I was a free hunter,” he says. He was able to observe his subjects at length, to befriend them, to gain their trust. “The masks fall from people’s faces, and you see their natural state and emotions. For a photographer, this is a gold mine,” he recalls.

In early 1989, he was working around the USSR’s border with Afghanistan. Three days before the withdrawal, Khabarov found himself on the Soviet side. Worried he would miss the final days, he asked Boris Gromov, the last Soviet commander of the war, if he could return. “He turned to me and said, ‘Are you f—ing crazy?’ But he’s a cool guy. He gave me his armored personnel carrier and said, ‘Just go.’ ”

Khabarov and a colleague raced across 300 miles of Afghan terrain in search of great photos before Soviet troops stopped them from going further. “Everyone was leaving, and we were trying to get back in. That ended up being some of the best photography I took in Afghanistan.” The airborne forces were jetting away; soldiers packed away their munitions; mothers slathered their returning sons with kisses. Khabarov was one of the last Soviets to leave the country, walking out by foot on the final day of the withdrawal, 30 years ago Friday.

Sappers after demining a mountain road in Jalalabad, Afghanistan. (Photo by Viktor Khabarov)

Paratroopers and caravan in Bagram, Afghanistan. (Photo by Viktor Khabarov)

Commander of a platoon, Sergey Semyonov, in Charikar, Afghanistan. (Photo by Viktor Khabarov)

Last day on the Afghan soil, a soldier takes ammunition back, in Hairatan, Afghanistan. (Photo by Viktor Khabarov)

A wounded paratrooper looks at the picture of his killed friends in Bagram, Afghanistan. (Photo by Viktor Khabarov)

Soviet soldiers are photographed at a Buddhist monastery in Bamiyan, Afghanistan. (Photo by Viktor Khabarov)

A female rebel in Kabul, Afghanistan. Photo taken at a parade in Kabul in honor of the pro-Communist Saur Revolution. She was from the women’s battalion of the people’s militia (one of the anti-imperial groups that participated in the coup d’etat). (Photo by Viktor Khabarov)

Wounded paratrooper in Panjshir Valley, Afghanistan. (Photo by Viktor Khabarov)

Soldier after a mission in Panjshir Valley, Afghanistan. (Photo by Viktor Khabarov)

A fighter for Afghan government forces in Kabul, Afghanistan. (Photo by Viktor Khabarov)

Soldiers upon completion of their service in Kabul, Afghanistan. (Photo by Viktor Khabarov)

In Sight is The Washington Post’s photography blog for visual narrative. This platform showcases compelling and diverse imagery from staff and freelance photographers, news agencies and archives. If you are interested in submitting a story to In Sight, please complete this form.

More on In Sight:

Looking at the war in Syria through a Syrian photographer’s eyes

The Tet Offensive: 50 years later, photographers and memories still haunt Vietnam War photographer Don McCullin

‘War can feel distant at times like that, but it can also feel never-ending’: Ashley Gilbertson’s photographs of bombing sites in Nigeria