How long was the Soviet-Afghan war?
The question of how long was the Soviet-Afghan war is not as simple as it seems. Most people think, that they can answer this question by approximating a decade. But is this correct?
Did the invasion happen in December 1979?
The official history states, that the Soviet invasion of Afghanistan started on 25th of December 1979. And while it is technically true - the majority of armed personnel with hostile intent only crossed the border on that day, Soviet troops were present on Afghan soil long before the official invasion was launched.
In July 1979, a battalion from the 111th Guards Parachute Regiment of the 105th Airborne Division arrived in Bagram, which, after the disbandment of the division in the autumn of 1979, was transferred to the 345th Airborne Regiment. This was the first military unit of the Soviet Army in Afghanistan.

One can argue that they were not performing any war actions at the time, and that is technically true. However, this regular military unis was present in Bagram unofficially, for half of the year, with weapon systems, disguised as technical personnel. Later on, they participated in overthrowing the Afghan government. So, despite the official and popular opinion, I would argue that the invasion has started back in July 1979, rather than in December of the same year.
Full scale Soviet invasion of Afghanistan in December 1979
It is well known, that the full scale invasion started on 25th of December 1979. This was the day when the majority of military units of 40th Army crossed the border of Afghanistan and starter their movement towards Afghan cities.

Such an offensive was prepared beforehand, both inside the Soviet Union and inside the Afghanistan. On November 27, 120 personnel arrived in Afghanistan on An-22 aircraft from the Gostomel airfield to organize communication between the future command of the Soviet troops in Kabul and military advisers at the divisions of the DRA Armed Forces. The transfer was handled by the 10th GRU Department. Before the dispatch itself, the staff did not know where they was going. The entire personnel was issued civilian clothes of non-Soviet production. These people were later responsible for setting up communication nodes.
Sometime between 9th and 12th of December the infamous "Muslim battalion" aka 154 ooSpN unit has arrived to Afghanistan. On 14th of December a battalion of 345th Airborne Regiment was transferred to Bahram airfield. These two units would later participate in the military coup - the assassination of the Afghan leader Hazifullah Amin.
The long process of Soviet withdrawal from Afghanistan
In 1985, Soviet leader Mikhail Gorbachev began to withdraw Soviet troops from Afghanistan, and by February 1989, the last Soviet troops had left the country. However, the war continued in Afghanistan, with the Afghan government forces and Mujahideen continuing to fight until the fall of the government in 1992. The war had a profound impact on Afghanistan and the region, leading to years of instability, civil war, and the rise of the Taliban regime.

The actual Soviet withdrawal from Afghanistan was done in two big waves. First wave started on 15th of May 1988, when first six regiments dislocated in the northern provinces were withdrawn from Afghanistan back to the Soviet Union.
All other units were wither withdrawing during the course of the same year or moved all at once in the February of 1989. The last days of the withdraw were very chaotic, even though the Soviet command tried to show otherwise. We will have a separate article on that.

Did the last Soviet soldier actually left Afghanistan on 15th of December 1989?
Well, just like with the invasion, the short answer is no. In the absolutely classical move of Soviet state propaganda, the commander of 40th Army, General Boris Gromov declared to the TV-cameras, that he is the last soviet "soldier" leaving Afghanistan. This of course, was not true.

To begin with, he did not account for all the Soviet prisoners of war, who were left in captivity of the Afghan Mujahideens. These people were incredibly unlucky, since after the collapse of the Soviet Union in 1991, no real work was done by the central government to get prisoners out of the Afghanistan. Work was done by veteran's organization, local governments and families, but of course their resources were limited.
Secondly, Soviet border guard units were covering the whole withdrawal process in the norther regions of Afghanistan. Many of them did not leave before the last official column, but instead stayed in Afghanistan for the next couple of days, withdrawing on their own. And while this is more of a technicality, some other border guard units were stationed inside Afghanistan for the whole 1989, still participating in occasional operations and firefights, protecting the Soviet border. Some border guards officers, attached to Afghan border guard units would stay inside Afghanistan until early 1990.
Summary
So, as usual, the answer to an obvious question turns out to be far more complicated. Official duration of the war counts as 9 years 1 month and 19 days, which only covers the presence of the majority of Soviet military regiments from 25th of December 1979 until 15th of February 1989. But as you have now learned from this article, the military presence was actually more than a year longer, just not on the same scale.