I've been wondering this for awhile... thanks if you can shed a little light on this for me!
First, define "lose" in this case. Because if USSR has lost in Afghanistan, then USA lost in both Iraq and in very same Afghanistan. Do you mean withdrawal of troops?
Let's compare:
In WW2 Germany capitulated and was occupied.
USSR did not capitulate to insurgents and pro-USSR regime (Babrak Karmal was changed to Nadjib, who added -ullah) actually was quite well until 1992, when Yeltsin decided to cut off military help and most importantly - oil supply. With Air Force grounded and APC, tanks not moving it was impossible to hold off.
USSR did not evacuate it's embassy from Kabul same way USA did in Khanoi in 1976.
That's just to keep prospective, "loss" in Afghanistan and "loss" in WW2 just not directly comparable, IMO.
If you want to call an orderly withdrawal without any fighting (as opposition agreed to give a free pass and was afraid that any attack would allow OKSVA to stay) a "loss" - fine.
Second, several facts:
OKSVA was withdrawn per order from political leadership, according to Geneva agreements of 1988
OKSVA didn't loose any major engagement and all direct engagements resulted in either complete rout or retreat of opposing forces. For example, when insurgents cut off Khost garrison in 1987 and tried to take over the city, OKSVA conducted operation "Magistral" and de-blocked Khost. Several attempts of opposition to take Jalalabad have failed too. And that's when OKSVA started withdrawal.
Third, the nature of the conflict was very different:
OKSVA soldiers lacked motivation - it was a foreign country which clearly didn't want any imposed changes. During WW2, soviet soldiers were very strongly motivated to stop aggression and then make sure that Germany won't have a capability to do so in future.
Strategy was passive - most of the time OKSVA troops were busy guarding themselves and their supply convoys. For active strategy, GenShtab estimated that 3x more troops would be required and collateral losses would be extremely high (and they weren't low anyway). So active operations were conducted only when Afghan leadership requested or when insurgents were threatening supply routes.
It was a proxy war - islamist rebels have financial and logistical support of USA. They were trained and organized raids from Pakistan and Iran territory. China was also supporting some rebel factions. Decisive, quick victory from purely military prospective would require massive strikes and raids outside of Afghanistan, which would lead to huge political issues (read: WW3)
Sources
Lester W. Grau - The Bear Went Over the Mountain: Soviet Combat Tactics in Afghanistan, 2013 Best source about OKSVA tactics in English - that I know of. It's a fresh edition, first edition was published in 1995 if I remember right.
Michael A. Gress, Lester W. Grau - The Soviet-Afghan War: How a Superpower Fought and Lost, 2002 Michael Gress served in OKSVA and provided some unique material. Lester Grau edited and commented materials.
Peter Tomsen - The Wars of Afghanistan: Messianic Terrorism, Tribal Conflicts, and the Failures of Great Powers (Google eBook), 2013 Just published - I haven't read it yet, but maps and tables look legit. Tons of reliable sources I know of are cited.
I could cite a bunch of russian sources, but I'm getting lazy :-)