From the New York Times:
Three successive American presidents have promised victory in Afghanistan, even if they each defined it differently. Each experienced failures of political will, and on the battlefield…
The British retreated in 1842 after suffering 4,500 killed, amid massacres that preceded the invention of the roadside bomb. They gave up their sovereignty over the country in 1919, in another retreat that heralded the beginning of the unwinding of an empire.
The Soviet Union abandoned its decade-long effort to control the country in 1989, months before the fall of the Berlin Wall marked the collapse of the Communist superpower. That led to the chaos and power vacuums that Bin Laden exploited, and that the United States vowed it would never again allow to fester.
From The Encyclopedia Britannica:
These uprisings, along with internal fighting and coups within the government between the People’s and Banner factions, prompted the Soviets to invade the country on the night of December 24, 1979, sending in some 30,000 troops and toppling the short-lived presidency of People’s leader Hafizullah Amin…
The war in Afghanistan became a quagmire for what by the late 1980s was a disintegrating Soviet Union. (The Soviets suffered some 15,000 dead and many more injured.) Despite having failed to implement a sympathetic regime in Afghanistan, in 1988 the Soviet Union signed an accord with the United States, Pakistan, and Afghanistan and agreed to withdraw its troops. The Soviet withdrawal was completed on February 15, 1989, and Afghanistan returned to nonaligned status.
From Rudyard Kipling in 1892: