How did the war in Afghanistan undermine the USSR?
There were several reasons why the USSR got involved in Afghanistan:
In 1978 control of Afghanistan was seized by the communist Babrak Karmal.
As soon as he took control of Afghanistan, Karmal "invited" the Red Army of the USSR to provide him with assistance against his opponents.
The USSR was determined that Afghanistan should not turn into a fundamentalist Muslim state as had recently happened in Iran.
Within the USSR, the war was very unpopular:
In military terms
The USSR responded to Karmal's request by sending 100,000 conscripts into Afghanistan within 4 months - most of these soldiers were unwilling conscripts taken from border regions and small villages. According to official statistics, 15,000 Soviet soldiers (mostly unwilling conscripts) lost their lives. According to unofficial statistics, 45,000 Soviet soldiers lost their lives.
In economic terms
The war was a terrible drain on the USSR
US politician Charlie Wilson worked with the CIA to ensure that millions of dollars worth of weapons were given to the rebels, so that the war became “Russia’s Vietnam”.
The war cost the USSR $8.2 billion a year for ten years, and ended with the USSR withdrawing in humilation.
The USA supplied Islamic "Freedom Fighters" with weapons to use against the USSR throughout the duration of the war.
Osama bin Laden fought the Soviets with weapons provided by the USA and by using highly effective guerrilla tactics.
Outside of the USSR, the war was very unpopular:
USA
President Carter of the USA described the invasion as "The greatest threat to world peace since World War Two". Charlie Wilson sponsored “Operation Cylcone” after his friend Joanne Herring arranged for him to visit injured Afghan children.
Afghanistan
It soon became clear to the USSR that this vast, inhospitable country would not be easily defeated.
Afghanistan was transformed into a weak state full of religious hatred: a breeding ground for terrorism.
Homes, animals, and precious irrigation systems in Afghanistan were destroyed, leaving the country barren and ruined.
A million Afghans were killed, and the survivors were a generation that had known only war, hatred, and fear.
Al-Q'aeda still uses American weapons it was given during the war to fight American and British troops today.
In the international community
There was a backlash against the USSR as a result of its actions.
Many countries boycotted the 1980 Moscow Olympics, including the USA.