The Kremlin had banked on a quick, trouble-free decapitation to solve the problem of a neighbor appearing to stray too far from Moscow’s orbit.

But after its vaunted army thundered across the border, very little went according to plan.

The invading troops met fierce resistance from outgunned fighters defending their homeland. International allies, including the United States, rushed to aid the underdogs. And a war that Moscow had seen as a chance to show off its might became instead a bloody and embarrassing display of weakness — one that threatened the stability of its deeply entrenched regime.

So has gone Russia’s stumbling, five-week-old invasion of Ukraine. But the same description applies to the Soviet Union’s ill-fated adventure in Afghanistan, which precipitated collapse at home and the Cold War’s end.

Now the history of that four-decade-old conflict looms over Russian President Vladimir Putin’s decision-making as he tries to navigate through a self-inflicted quagmire. Veterans of the Afghanistan war say he has already failed to heed some of its most critical lessons, including by overestimating his military’s capabilities and misjudging his adversaries.

“The Russians underestimated the Afghans in the 1980s,” said Bruce Riedel, who worked on the CIA’s covert program to aid the rebels. “They seem to have underestimated the Ukrainians today.”

Riedel said there’s irony in that failure: Putin, in invading Ukraine, has appeared bent on restoring the glory lost when the Soviet Union broke up, an event he has described as the “greatest geopolitical catastrophe of the century.”

Yet, by making some of the same mistakes that haunted Soviet leaders until the day their empire fell apart, Putin has put Russian power — not to mention his own future — in doubt.

“In setting out to reverse history,” another CIA veteran of the Afghanistan war, Milton Bearden, recently wrote in Foreign Affairs, “he may instead be repeating it.”

Of course, there are vast differences between Ukraine now and Afghanistan then. To name a few: Ukraine’s government is democratically elected, while Afghanistan already had a Soviet-backed communist regime before the invasion. Today’s war is being fought alarmingly close to NATO’s front lines, rather than a battlefield seen as distant to many in the West. Russian troops have been in Ukraine for barely over a month; the Soviets lingered in Afghanistan for nearly a decade.

Yet, if anything, analysts say, this war is going far worse for Moscow.

When Soviet troops poured over the Hindu Kush Mountains and into Afghanistan on Christmas Eve in 1979, they achieved initial success. Their goal was to eliminate Afghan leader Hafizullah Amin, whom the KGB falsely believed to be having a dalliance with the CIA. Soviet paramilitaries did just that, gunning him down in his Kabul palace.

The war, it appeared, had been won.

In Ukraine, Russia analyst Anatol Lieven said, Putin was apparently hoping for a similarly quick victory, one in which “the Russians would march in, [Ukrainian President Volodymyr] Zelensky would run away, and the Ukrainian resistance would collapse.”

“The difference with Afghanistan,” said Lieven, who covered the Afghanistan war as a journalist, “is that that plan failed.”

It would ultimately fail in Afghanistan, as well. But that would take longer — just as it later did for the United States’ own star-crossed intervention in Afghanistan.

In plotting to oust Amin, the Soviets had not counted on the fervor or resilience of Afghan rebels — known as mujahideen — who launched a David vs. Goliath rebellion against what was then the world’s largest conventional army.

Nor had they anticipated the cohesion of their international adversaries, who banded together to hatch a secret strategy for bleeding the Red Army.

The Kremlin had believed that the United States and its president, Jimmy Carter, would be too distracted by domestic turmoil and by recent foreign policy flops to seriously engage on Afghanistan. But within weeks of the Soviet advance, crates of U.S.-funded weapons were being unloaded in the Pakistani port of Karachi, for onward delivery to the mujahideen.

Riedel, who was working in the CIA’s operations center on the night that Soviet paratroopers began landing in Afghanistan, said U.S. policymakers had rapidly seized on the idea that “this could be the Soviet Union’s Vietnam.” Washington could help by supplying money and arms to the rebels, funneling that assistance through Pakistani partners.

“The U.S. role [in Afghanistan] was basically the quartermaster of the war,” said Riedel, who now directs the Brookings Intelligence Project. “That’s the role that Biden and company envision for the U.S. again.”

As was true in Afghanistan, Moscow appears to have been caught off-guard by the backing that Ukraine is getting from beyond its borders. Before the invasion, NATO, the European Union and the United States were all racked by internal division. President Biden had just overseen his own humiliating retreat from Afghanistan and was believed to have little appetite for confrontation.

A Ukrainian soldier walks by a destroyed Russian fighting vehicle on the outskirts of Brovary, near Kyiv, on March 28, 2022. (Heidi Levine for The Washington Post)

But the West has shown unexpected unity in sticking up for Ukraine. And this time, the support is coming not in the shadows, but in the wide open.

The weaponry, too, is more sophisticated now. Much of the early assistance to the mujahideen came in the form of small arms, such as rifles, with antiaircraft Stinger missiles arriving only after years of combat.

In the case of Ukraine, the United States and NATO have supplied thousands of Stingers as well as thousands more antitank Javelins, weaponry that has dramatically raised the cost in Russian blood and treasure.

A top State Department official, Victoria Nuland, said this week that Russia has lost more than 10,000 troops — approaching the 15,000 dead that the Soviets acknowledged in Afghanistan. While the latter figure is widely believed to be an underestimate, the pace of casualties in this war is clearly much higher.

“In Afghanistan, it took nine years to wear the Soviet Union down,” said Lieven, who is a senior research fellow at the Quincy Institute for Responsible Statecraft. “It’s happening much quicker in the case of Ukraine.”

That’s one reason, Lieven said, that he believes Putin could seek a diplomatic off-ramp that allows him to cut his losses.

Moscow has sent mixed signals in recent days about its attitude toward negotiations, and analysts say that while an agreement is possible, it’s also conceivable that Putin opts to escalate.

That’s what Russia did in Chechnya in the 1990s. When initial Russian hopes of a lightning-fast victory faded, the military shifted to carpet bombing and besieging cities and towns. The result was a devastatingly costly war for both sides that left much of Chechnya in ruins.

In Ukraine — particularly in the southern port city of Mariupol — the Russian strategy has at times seemed to mimic the playbook in Chechnya.

When the Russian plan to seize Kyiv failed, “there was no backup plan,” said Thomas de Waal, a senior fellow at Carnegie Europe, “so they resorted to a massive, indiscriminate bombardment instead.”

Those tactics have left a dismal toll: The United Nations said this week that more than 4 million Ukrainians have fled the country since the war began. The U.N. human rights agency has confirmed the deaths of more than 1,200 civilians, although it says the true count is far higher.

More than a million Afghans are believed to have been killed during the Soviet occupation; some 6 million more became refugees.

“When I see these pictures of Ukrainians leaving their country, I relate to them,” Ali Ahmad Jalali said. “I had to leave my country, traveling over the mountains with my family.”

Jalali, who had been an Afghan army officer, later returned to join the rebels.

Initially, he said, “nobody thought the mujahideen would be able to force the Soviets out. The mujahideen themselves didn’t think they would be able,” said Jalali, who became Afghanistan’s interior minister after the Taliban government was deposed and who is now a professor at National Defense University. “They didn’t care. It was the right thing to do.”

But as Moscow’s losses accumulated, he said, “it broke the spell of Soviet invincibility.”

Mikhail Minakov, as a young Ukrainian, experienced that from within. He was training in military medicine and expected to be deployed to treat Soviet troops in Afghanistan. It was a scary prospect: His professor brought in veterans to speak to the class, men who had lost eyes or legs on the battlefield.

It is not clear how much Russians today know of the casualties their side is taking, given extreme controls on the media. But Minakov said Russians can’t help but be aware of the economic toll brought on by sanctions, which are reversing Putin’s primary achievements: economic integration with the West and a rising standard of living.

The brutality of war on Ukraine’s front lines
Russia announced on March 29 it would scale back its assault on Kyiv. But in the village of Moshchun, just 20 miles north of the capital, the battle raged on. (Video: Jon Gerberg, Jorge Ribas/The Washington Post, Photo: Heidi Levine for The Washington Post/The Washington Post)

“Putin has destroyed the social contract that brought him to power and kept him in power,” said Minakov, a senior adviser at the Kennan Institute.

That’s one reason, Minakov said, that he believes the Russian president — whose grip on power had long been considered unassailable — is far more vulnerable now than before the invasion began. But Putin, he said, is still dangerous and has shown he is not above dangling the threat of nuclear war.

It’s a risk, said Hudson Institute senior fellow Husain Haqqani, that cannot be taken lightly.

When Soviet troops were battling Afghan insurgents armed with U.S.-financed weapons in the 1980s, Haqqani said, both sides were careful to avoid undue escalation. The Americans stayed off the battlefield. The Soviets resisted expanding the fight into Pakistan. Pakistan’s leader, military dictator Mohammed Zia ul-Haq, talked often of keeping the war set to simmer, while never allowing it to boil over.

“The rules of the game were firmly established,” said Haqqani, who covered the war as a journalist and later became Pakistan’s ambassador to the United States. “The Soviets and Americans took the threat of nuclear conflict seriously.”

But now, he said, “Putin has upended the rules of the game.”

Adding to the peril: Pakistan was never a NATO member, but four countries on Ukraine’s border are: Poland, Romania, Slovakia and Hungary. If any are attacked, the alliance would be obliged to defend them.

As Putin’s options narrow, his unpredictability may grow, said Bearden, the former CIA officer. Less than three years after the last Soviet troops retreated across the Amu Darya River, the Soviet Union was no more. The Russian president, Bearden said, is acutely aware of that history — and will be doing all he can to avoid allowing his mistakes in Ukraine to turn fatal: “What I see Putin trying to do now is figure out, ‘How do I not let this thing bring me down?’ ”