They could, I believe. There are a number of things that have to happen:
1. Obviously, the USSR needs to reform successfully, which it could under a different leadership. I once wrote a
TL on the subject. The USSR can't win if it no longer exists.
2. The Afghan communists introduced a number of radical modernization reforms throughout the country that were deeply unpopular, particularly among the more traditional rural population and the established traditional power structures. The USSR needs to compel the Afghan communists to drop or mitigate the policies that were the most unpopular and perhaps introduce further reforms in a more gradualist fashion. In a society that's so deeply conservative and religious, a healthy respect for Islam and tradition is a necessity. You just can't change a society like that to a secular, atheist one overnight by force. That's just going to piss people off.
3. The regime was Stalinist in nature, i.e. extremely oppressive. If step 2 is carried out, 3 likely won't be necessary. That'll make them less unpopular.
4. "Afghanization" of the conflict ASAP. By that I mean that the strong Soviet presence should be reduced as soon as feasibly possible so the regime won't look like a puppet state and more like the legitimate government. Limit support to air support, artillery strikes, providing intelligence, spec ops, training Afghan soldiers and police and providing material and logistical aide while letting Afghan forces man the frontlines.