When the last Soviet tanks rumbled back home across a bridge on the border with Afghanistan 30 years ago, the withdrawal was hailed as a much-anticipated end to a bloody quagmire.
Since then, Moscow's view of the war has changed radically.
As Russia prepares to mark Friday's anniversary of the Soviet withdrawal, many see the 10-year Soviet war in Afghanistan as a necessary and largely successful endeavor. Just like the ongoing Russian campaign in Syria, the Afghan war is widely perceived as a legitimate action against United States-backed militants.
And in a twist of history, Russia also has emerged as an influential power broker in Afghanistan, mediating between feuding factions as it jockeys with Washington for influence in a country where a US-led coalition has been fighting for more than 17 years.
Ata Mohammad Noor, a former warlord who fought Soviet troops and served as governor of the northern Balkh province from 2004-2018, attended a meeting last week in Moscow that brought together former Afghan officials, opposition figures, and the Taliban.
"I don't think that Russia would like to repeat what it did in the past. It's totally different today," Mr. Noor said in an interview with The Associated Press. "On the other side, there have been 40 years of war in our country, and the Afghan people are all tired of war. People would support any country that would step forward to bring peace."
The statement carries particular weight coming from a man who played a key role in defeating the Soviet Army, was badly wounded in combat, and proudly recalls how his mujahedeen fighters destroyed countless Red Army tanks and dozens of warplanes.
After the long US involvement, Afghans are deeply critical of the coalition forces. Even those who fought in the 1980s give grudging credit to Moscow for leaving a legacy that outshines Washington's. They point out that Russian left behind a strong and disciplined Army and a 400-bed military hospital that is still among the country's best health facilities. Some note that while communist President Najibullah's government was ruthless, it was not wracked by the widespread corruption that has plagued Afghanistan's US-backed government.
The Soviet Union invaded Afghanistan in December 1979, driven by fears that the US could try to establish a foothold next to Soviet republics in Central Asia after losing Iran in the Islamic Revolution. Moscow's initial plans for a quick operation were derailed by fierce rebel resistance, and in the years of fighting that followed, the Soviet Union lost more than 15,000 troops, according to official data. Estimates of civilian casualties in that period vary widely, from more than 500,000 up to 2 million.
The Soviet intervention drew strong international condemnation and imposed a heavy burden on the struggling Soviet economy. Soviet leader Mikhail Gorbachev ordered the pullout amid his efforts to conduct liberal reforms and end confrontation with the West. Afghanistan's communist government held for three more years, collapsing shortly after the December 1991 breakup of the Soviet Union.
Nikita Mendkovich, a Moscow-based expert on Afghanistan, said Russia's economic meltdown after 1992 resulted in the abrupt termination of fuel supplies to Afghanistan, triggering the fall of Mr. Najibullah.
"The tragedy of Afghanistan was one of many other tragedies caused by the Soviet breakup," he said.
Mr. Mendkovich emphasized the changing public perception of the war, saying that it's now widely seen as "painful, but necessary and even inevitable."
Many Russian officials and lawmakers argue that the US performance in Afghanistan has been far less successful than that of the Soviet Union.
"The army trained by the Soviet Union could stand alone for three years," said Zamir Kabulov, President Vladimir Putin's envoy for Afghanistan. "As for this one trained by the Americans, you listen to the Afghans. They aren't sure about even one month."
He acknowledged that the Soviet Union made many errors in Afghanistan, driven by communist dogmas and ignoring local conditions.
"The Soviet leadership has become hostage of its own decision," he said. "They wanted to look at Afghanistan as a new socialist state. That was a mistake."
In one example, he recalled how Soviet advisers stubbornly tried to conduct a socialist-style land reform, distributing tracts that belonged to tribal leaders to farmers, who then turned it back to original owners.
Mr. Kabulov charged that the US ignored the Soviet lessons and made the same mistake in trying to foster the creation of a Western-style democracy in Afghanistan.
"It's a pity that our American colleagues don't learn history; they prefer to make history," Kabulov said with a sardonic smile.
He noted that the US support for the mujahedeen played a key role during the Soviet war, adding that the US later paid the price for backing insurgents like Osama bin Laden who was among those who fought the Soviets in Afghanistan.
"They [the Americans] were obsessed with building Vietnam for the Soviet Union," Kabulov said. "They believed everything is good to crush bloody Russians, so they got it back now."
Afghanistan veteran Sergey Zhidkov recalled that in the early stages of the Soviet war, clashes were rare and roads were relatively safe, but the rebels quickly strengthened and ambushes became routine.
"We were escorting convoys of fuel trucks to cover them from attacks," he told the AP. "The most painful thing was losing comrades. It was like we were sitting and talking, and then bang and he's dead."
Noor, who joined the mujahedeen when he was 19 and became a top warlord with 20,000 men under his command, recalled formations of Soviet helicopter gunships sweeping overhead like "flocks of birds." He described one Soviet air raid that destroyed a village of 500 families, killing most of the residents.
Noor said the deliveries of US Stinger anti-aircraft missiles to the mujahedeen played a significant role, allowing them to strike Soviet jets. He noted that his fighters downed more than 20 Soviet aircraft, including three big Antonov military transport planes.
He said he was badly wounded while leading his fighters to break through the Russian cordons.
"There was only one way out, but a tank regiment was blocking that way," he said, describing how he fired a weapon at a Soviet tank just as another one hit his position.
"I wanted to see how the tank burned when I fired. That is when the other tank fired at me," Noor said with a smile. "I got hit with 32 pieces of shrapnel, and those 32 scars are still on my body."
Noor described the Soviet pullout as a source of pride for Afghans.
"The withdrawal of the Soviet Union was a historic day," he said. "A poor nation with lots of problems, we defeated a superpower."
In Russia, many veterans blame Gorbachev for a hasty pullout that squandered the hard-fought gains, and they hold Russia's first president, Boris Yeltsin, responsible for the demise of Najibullah.
"We could have done many things differently. We could have done better to minimize losses," said Frants Klintsevich, a veteran who serves as a lawmaker in Russia's upper house. "And in the end we just gave up everything and also ruined the Soviet Union."
This story was reported by The Associated Press. Iuliia Subbotovska contributed to this report.