The Soviets invaded Afghanistan to ensure that a pro-Soviet regime would be in power in the country. The Soviet invasion shocked the West, as it was the first direct use of Soviet combat troops outside the region of the Warsaw Pact.
In response to the invasion, the United States imposed a grain embargo on the Soviets. It also withdrew from the 1980 Olympic Games in Moscow. More importantly, the Soviet invasion resulted in increased defense spending in the United States.
By this time, a single leader was developing in the opposition: the Ayatollah Khomeini, a leading Muslim fundamentalist living in exile in France. On July 16, 1979, the Shah left the country for a "vacation." Two weeks later, the Ayatollah had returned to lead a new fundamentalist government.
The Soviet invasion was vigorously opposed by the Afghan guerrillas (who were called Mujdeen). They were armed by the United States, and ultimately fought the Soviets to a standstill. The Soviets were forced to withdraw, as Afghanistan had become the equivalent of Vietnam in American foreign policy.