The struggle between Afghanistan and the Soviet Union has had a longstanding effect on Afghanistan, and is one of the main causes of our war there today with the Taliban. The Soviets may have been bad for Afghanistan, but in many ways the Taliban was worse.
The Soviet-Afghan War lasted from 1978 until 1992. The Soviet Union had attempted to maintain a puppet state, but the pro Soviet government was overthrown leading to a protracted conflict where the indigenous people effectively neutralized the technologically advanced weaponry that the Soviet Union had brought to bear. The conflict finally concluded when the Afghans began to receive comparable weaponry from the United States.
However, for much of the time, the Soviets controlled the urban areas and the Afghans controlled the rural areas. In the early 90's, reflecting the new spirit of "openness, the soviet citizenry began to balk at supporting the conflict, and they withdrew.
The comparison with the US involvement in Vietnam is interesting -- both were long wars, fought asymmetrically, once side being technologically advanced while the other was not; one side controlling the cities while the other controlled the countryside. Furthermore, the conflict was finally concluded after popular sentiment moved against the war.