In 1979, the Soviet leadership sent troops to Afghanistan, justifying that move not just by the desire to help friendly elements there but also by the need to stabilize a neighboring country.
The real reason is very different, and is clearly spelled out in a brief memo KGB head Andropov sent to Soviet dictator Brezhnev on December 1, 1979 (events leading up to these events can be seen here):
1. After the coup and the murder of Taraki in September of this year, the situation in Afghanistan began to undertake an undesirable turn for us. The situation in the party, the army and the government apparatus has become more acute, as they were essentially destroyed as a result of the mass repressions carried out by Amin.
At the same time, alarming information started to arrive about Amin's secret activities, forewarning of a possible political shift to the West. [These included:] Contacts with an American agent about issues which are kept secret from us. Promises to tribal leaders to shift away from USSR and to adopt a "policy of neutrality." Closed meetings in which attacks were made against Soviet policy and the activities of our specialists. The practical removal of our headquarters in Kabul, etc. The diplomatic circles in Kabul are widely talking of Amin's differences with Moscow and his possible anti-Soviet steps.
All this has created, on the one hand, the danger of losing the gains made by the April  revolution (the scale of insurgent attacks will increase by spring) within the country, while on the other hand - the threat to our positions in Afghanistan (right now there is no guarantee that Amin, in order to protect his personal power, will not shift to the West). [There has been] a growth of anti-Soviet sentiments within the population.
2. Recently we were contacted by group of Afghan communists abroad. In the course of our contact with Babrak [Karmal] and [Asadullah] Sarwari, it became clear (and they informed us of this) that they have worked out a plan for opposing Amin and creating new party and state organs. But Amin, as a preventive measure, has begun mass arrests of "suspect persons" (300 people have been shot).
In these conditions, Babrak and Sarwari, without changing their plans of opposition, have raised the question of possible assistance, in case of need, including military.
We have two battalions stationed in Kabul and there is the capability of rendering such assistance. It appears that this is entirely sufficient for a successful operation. But, as a precautionary measure in the event of unforeseen complications, it would be wise to have a military group close to the border. In case of the deployment of military forces we could at the same time decide various questions pertaining to the liquidation of gangs.
The implementation of the given operation would allow us to decide the question of defending the gains of the April revolution, establishing Leninist principals in the party and state leadership of Afghanistan, and securing our positions in this country.
Eleven days later the Soviet Politburo approved the invasion, or the "measures", of "A" and during Christmas week 150,000 Soviet troops crossed the border, the capital was attack, the presedential palace stormed by KGB commandos and Amin executed. His economic advisor, Abdul Shams, escaped and lived to tell about it (parts 4 and 6, in other parts of his speech about advanced CIA aid not reaching the Muj are mistaken, because the stingers did in deed make it to the Muj).
back to Gorby NYT:
The greatest mistake was failing to understand Afghanistan’s complexity — its patchwork of ethnic groups, clans and tribes, its unique traditions and minimal governance.
And the fact that you tried to impose atheism on a deeply religious people. And the fact that they tried to destroy Pakistan through proxy a few years before the invasion of Afghanistan, making USSR not very popular with Pakistan.
The result was the opposite of what we had intended: even greater instability, a war with thousands of victims and dangerous consequences for our own country. On top of it, the West, particularly the United States, kept fueling the fire in the spirit of the Cold War; it remained ready to support just about anyone against the Soviet Union, giving no thought to possible long-term consequences.
First off, you better believe we didn't want your commie stooges in control of the country. But there is a myth here he continues to push, and I'll resort to the 9/11 commission in reply:
Saudi Arabia and the United States supplied billions of dollars worth of secret assistance to rebel groups in Afghanistan fighting the Soviet occupation. This assistance was funneled through Pakistan: the Pakistani military intelligence service (Inter-Services Intelligence Directorate, or ISID), helped train the rebels and distribute the arms. But Bin Ladin and his comrades had their own sources of support and training, and they received little or no assistance from the United States.
As part of perestroika in the mid-1980s, the new Soviet leadership drew conclusions from our troubles in Afghanistan.
El Rushbo quoted Gorby's book to describe what perestroika was all about. His book says - "I stress once again, perestroika is not some kind of illumination or revelation. To restructure our life means to understand the objective necessity for renovation and acceleration, and that necessity emerged in the heart of our society. The essence of perestroika lies in the fact that it unites socialism with democracy and revives the Leninist concept of socialist construction, both in theory and in practice. Such is the essence of perestroika which accounts for its genuine revolutionary spirit and its all-embracing scope."
We made two crucial decisions. First, we set the goal of withdrawing our troops. Second, we intended to work with all parties in the conflict and with the governments involved to achieve national reconciliation in Afghanistan and make it a peaceful and neutral country that threatened no one.
This is not true, recently, he personally talked about the communist gov he in deed did leave behind until it's eventual overthrow.
To succeed, we needed sincere and responsible cooperation from all sides. The Afghan government was ready to compromise and went more than halfway to achieve reconciliation. In a number of regions, things started to improve.
However, Pakistan, particularly its top brass, and the United States blocked all avenues to progress. They wanted one thing: the withdrawal of Soviet troops, which they thought would leave them in full control. By denying Afghan President Mohammad Najibullah’s government even minimal support, Boris Yeltsin played into their hands when he took office.
We don't consider Soviet imposed communist Government as "progress". And your country should learn how to treat it's veterans.
During the 1990’s, the world seemed indifferent to Afghanistan. In that decade the country’s government fell into the hands of the Taliban, who turned Afghanistan into a haven for Islamic fundamentalists and an incubator of terrorism.
Yep, we screwed up that part.
That's basicly the cold war context of Gorby's thing. I'll update this post more tommorow, it's late.