Prior to the arrival of Soviet troops, the pro-Soviet Nur Mohammad Taraki government took power in a 1978 coup and initiated a series of radical modernization reforms throughout the country. Vigorously suppressing any opposition from among the traditional Muslim Afghans, the government arrested thousands and executed as many as 27,000 political prisoners. By April 1979 large parts of the country were in open rebellion and by December the government had lost control of territory outside of the cities. In response to Afghan government requests, the Soviet government under leader Leonid Brezhnev first sent covert troops to advise and support the Afghan government, but on December 24, 1979, began the first deployment of the 40th Army. Arriving in the capital Kabul, they staged a coup, killing the Afghan President, and installing a rival Afghan socialist (Babrak Karmal).
Mujahideen fighters in the Kunar Province of Afghanistan in 1987
In January 1980, foreign ministers from 34 nations of the Islamic Conference adopted a resolution demanding "the immediate, urgent and unconditional withdrawal of Soviet troops" from Afghanistan, while the UN General Assembly passed a resolution protesting the Soviet intervention by a vote of 104–18. Afghan insurgents began to receive massive amounts of aid, military training in neighboring Pakistan and China, paid for primarily by the United States and Arab monarchies in the Persian Gulf.
As documented by the National Security Archive, "the Central Intelligence Agency (CIA) played a significant role in inserting U.S. influence in Afghanistan by funding military operations designed to frustrate the Soviet invasion of that country. CIA covert action worked through Pakistani intelligence services to reach Afghani rebel groups." Soviet troops occupied the cities and main arteries of communication, while the mujahideen waged guerrilla war in small groups operating in the almost 80 percent of the country that escaped government and Soviet control. Soviets used their air power to deal harshly with both rebels and civilians, leveling villages to deny safe haven to the enemy, destroying vital irrigation ditches, and laying millions of land mines.
Soviet soldiers conducting training
By the mid-1980s the Soviet contingent was increased to 108,800 and fighting increased throughout the country, but the military and diplomatic cost of the war to the USSR was high. By mid-1987 the Soviet Union, now under reformist leader Mikhail Gorbachev, announced it would start withdrawing its forces. The final troop withdrawal started on May 15, 1988, and ended on February 15, 1989. The war was considered part of the Cold War. Due to its length it has sometimes been referred to as the "Soviet Union's Vietnam War" or the "Bear Trap" by the Western media, and thought to be a contributing factor to the fall of the Soviet Union.
(source)