The Soviet–Afghan War lasted over nine years, from December 1979 to February 1989.
Insurgent groups known collectively as the mujahideen, as well as smaller Maoist groups, fought a guerrilla war against the Soviet Army and the Afghanistan government, mostly in the rural countryside. The mujahideen groups were backed primarily by the United States, Saudi Arabia, and Pakistan, making it a Cold War proxy war. Between 562,000 and 2,000,000 civilians were killed and millions of Afghans fled the country as refugees.
In 1978, Afghanistan's communist party took power after a coup, and initiated a series of radical modernization reforms throughout the country that were deeply unpopular, particularly among the more traditional rural population and the established traditional power structures. The government's Stalinist-like nature of vigorously suppressing opposition, executing thousands of political prisoners and ordering massacres against unarmed civilians, led to the rise of anti-government armed groups, and by April 1979 large parts of the country were in open rebellion.
Eventually the Soviet government deployed its army in December 1979. Arriving in the capital, they killed the president and installed a Soviet loyalist. 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.
Afghan insurgents began to receive massive amounts of aid and military training in neighboring Pakistan and China, paid for primarily by the United States and Arab monarchies in the Persian Gulf. The CIA played a significant role in asserting 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 Afghan 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 outside government and Soviet control.
The Soviets initially planned to secure towns and roads, stabilize the government, and withdraw within six months or a year. But they were met with fierce resistance from the guerillas, and stuck in a bloody war that lasted nine years. By the mid-1980s, the Soviet contingent was increased to 108,800 and fighting increased, 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 ended on February 15, 1989, leaving the government forces alone in its battle against the insurgents, which continued until 1992 when the former Soviet-backed government collapsed.
Due to its length, the war has sometimes been referred to as the "Soviet Union's Vietnam War." The Soviets' failure at the war is thought to be a contributing factor to the fall of the Soviet Union.