Gorbachev, former head of the USSR wrote in the NYT:
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
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.
Information not described in the memo, and what happened next, was best described by Amin's Economic advisor, Abdul Shams