On 15 February 1989 the last Soviet combatant forces left Afghanistan, ending a process of withdrawal that had begun on 15 May 1988. The military leader in charge of the withdrawal was Colonel-General Boris Gromov.
According to Wikipedia: “Planning for the withdrawal of the Soviet Union (USSR) from the Afghanistan War began soon after Mikhail Gorbachev became the General Secretary of the Central Committee of the Communist Party of the Soviet Union. Under the leadership of Gorbachev, the Soviet Union attempted to consolidate the People’s Democratic Party of Afghanistan’s hold over power in the country, first in a genuine effort to stabilize the country, and then as a measure to save face while withdrawing troops. During this period, the military and intelligence organizations of the USSR worked with the government of Mohammad Najibullah to improve relations between the government in Kabul and the leaders of rebel factions.”
Source: Soviet withdrawal from Afghanistan, Wikipedia