It was the Vietnam syndrome for the USSR as a superpower: impossible to run away from that country. Afghanistan is traditionally an Islamic nation. Afghanistan has a history of conquest and it became a focal-point for Cold War conflict. Afghanistan was strategically important for oil as well. US aided Islamic fundamentalists to counter-balance the USSR’s aggression.
In 1978 a communist government emerges. The Afghan government of Taraki looked to the Soviet Union for support. Moscow sent hundred of advisors, military trainers, and military supplies to Afghanistan in 1978 – 1979. Afghanistan was an agricultural country and the government advocated land reform allowing peasants to achieve egalitarian objectives. Women were encouraged to stop wearing veils and began schooling. The rural communities opposed these changes and the Mullahs felt that the communists were trying to destroy Islamic tradition. God must decide who is rich or poor according to the Mullahs. As retaliation against secularist communist repression, Mullahs attempted to burn schools. The Kabul Taraki (http://en.wikipedia.org/wiki/Nur_Muhammad_Taraki) government was trying to build socialism for 5 years running, the regime was vastly ignorant of rural Afghanistan. There was a holy war declared against the godless communist government of Afghanistan. At the same time, Russia was feared to move south into Afghanistan to seize oil in Iran as was feared by Jimmy Carter. The Shahs fall in Iran meant the US had few allies in the region. The US gave covert aid in July 1979 to the Mujahadeen.
The invasion by the USSR into Afghanistan was an affront against US foreign policy interests. The Afghanistan government was replaced by Amin however, he realized that the USSR wanted him out. The Russians were concerned that Amin would ask for US assistance and support US invasion. Russian sent troops in after Americans had deployed cruise missiles to threaten the USSR’s military superiority in the region. The Politburo in the USSR a) feared Islamic fundamentalism in Afghanistan, b) if the USSR did not enter Afghanistan some one else would, c) there was instability between the USSR/Afghanistan border. KGB special-forces killed Amin in his palace.
Karmal was the president of Afghanistan. The Soviet invasion of Afghanistan was seen as a threat to world order because it was the first invasion outside of the Warsaw Pact. Jimmy Carter issued a threat that if the USSR invaded Pakistan or Iran he would respond with Nuclear War. The soviet invasion was widely condemned at the UN. The 1980 Moscow Olympics were boycotted. The US supported the Mujahadeen in a clandestine manner: God was on their side. The idea was to allow for the bleeding of the USSR in Afghanistan. US bought Soviet arms from Czechloslovakia (corrupt), Egypt, and China. Pakistan wanted a strongly Islamic neighbour even with nuclear weapons interests and drugs as long as the Afghan resistance was supported.