[deleted]
The Soviet invasion began when it overthrew the existing Communist government in Kabul and replaced it with a new one. Prior to the Soviet invasion the Afghan Communist party was deeply fractured and beset by conflicts between two factions within the party. Eventually Hafizullah Amin was able to take power in the party but he was viewed as potentially anti-USSR by the Soviet politburo. Despite reluctance to intervene, the USSR was ultimately afraid that Amin would do the same thing as Sadat (president of Egypt) did earlier in the decade: which is to realign from the Soviet bloc towards the west and create an unfriendly state on the Soviet border.
The first act of the invasion was Soviet special forces storming the Afghan presidential palace. Amin was killed in the attack and his government replaced with one which would be more pliable to Soviet interests. Under such circumstances, it is difficult to construe the Soviet as aiding a legitimate government so much as it disposed one.