Given this paragraph about the Cold War, why did the Soviets pull out of their war in Afghanistan?

After World War II, parts of Eastern and Central Europe, including East Germany and eastern parts of Austria were occupied by Red Army according to the Potsdam Conference.[149] Dependent communist governments were installed in the Eastern Bloc satellite states.[150] After becoming the world's second nuclear power,[151] the Soviet Union established the Warsaw Pact alliance,[152] and entered into a struggle for global dominance, known as the Cold War, with the rivaling United States and NATO.[153] After Stalin's death in 1953 and a short period of collective rule, the new leader Nikita Khrushchev denounced Stalin and launched the policy of de-Stalinization, releasing many political prisoners from the Gulag labor camps.[154] The general easement of repressive policies became known later as the Khrushchev Thaw.[155] At the same time, Cold War tensions reached its peak when the two rivals clashed over the deployment of the United States Jupiter missiles in Turkey and Soviet missiles in Cuba.[156]

In 1957, the Soviet Union launched the world's first artificial satellite, Sputnik 1, thus starting the Space Age.[157] Russian cosmonaut Yuri Gagarin became the first human to orbit the Earth, aboard the Vostok 1 manned spacecraft on 12 April 1961.[158] Following the ousting of Khrushchev in 1964, another period of collective rule ensued, until Leonid Brezhnev became the leader. The era of the 1970s and the early 1980s was later designated as the Era of Stagnation. The 1965 Kosygin reform aimed for partial decentralisation of the Soviet economy.[159] In 1979, after a communist-led revolution in Afghanistan, Soviet forces invaded the country, ultimately starting the Soviet–Afghan War.[160] In May 1988, the Soviets started to withdraw from Afghanistan, due to international opposition, persistent anti-Soviet guerrilla warfare, and a lack of support by Soviet citizens.[161]

From 1985 onwards, the last Soviet leader Mikhail Gorbachev, who sought to enact liberal reforms in the Soviet system, introduced the policies of glasnost (openness) and perestroika (restructuring) in an attempt to end the period of economic stagnation and to democratise the government.[162] This, however, led to the rise of strong nationalist and separatist movements across the country.[163] Prior to 1991, the Soviet economy was the world's second-largest, but during its final years, it went into a crisis.[164]

By 1991, economic and political turmoil began to boil over as the Baltic states chose to secede from the Soviet Union.[165] On 17 March, a referendum was held, in which the vast majority of participating citizens voted in favour of changing the Soviet Union into a renewed federation.[166] In June 1991, Boris Yeltsin became the first directly elected president in Russian history when he was elected president of the Russian SFSR.[167] In August 1991, a coup d'état attempt by members of Gorbachev's government, directed against Gorbachev and aimed at preserving the Soviet Union, instead led to the end of the Communist Party of the Soviet Union.[168] On 25 December 1991, following the dissolution of the Soviet Union, along with contemporary Russia, fourteen other post-Soviet states emerged.

The Soviets withdrew from the Soviet-Afghan War beginning in May 1988 due to international opposition, persistent anti-Soviet guerrilla warfare, and a lack of support by Soviet citizens.