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 Democratic Republic of Afghanistan government, mostly in the rural countryside.

The war derives from a 1978 coup when Afghanistan's communist party took power, initiating a series of radical modernization reforms throughout the country. These reforms were deeply unpopular among the more traditional rural population and established power structures. The repressive nature of Soviet Afghanistan, which vigorously suppressed opposition including the execution of thousands of political prisoners, led to the rise of anti-government armed groups and by April 1979 large parts of the country were in open rebellion.

The ruling party itself experienced deep rivalries, and in September 1979 the President, Nur Mohammad Taraki, was murdered under orders of the second-in-command, Hafizullah Amin, which soured relations with the Soviet Union. Eventually the Soviet government, under leader Leonid Brezhnev, decided to deploy the 40th Army on December 24, 1979. Arriving in the capital Kabul, they staged a coup, killing president Amin and installing Soviet loyalist Babrak Karmal from a rival faction.

More Info: en.wikipedia.org