AS its last troops leave Afghanistan, Moscow is bracing itself for a tough year in Soviet-Afghan relations. Soviet analysts confess that they have no idea what will happen next, but are prepared for their worst fear: the arrival in power of a fundamentalist Islamic government flushed with victory. The Soviets' first task will be to build a modus vivendi with the new regime. They will also have to decide how to react if their ally, the ruling People's Democratic Party of Afghanistan (PDPA), abandons Kabul and takes to the hills to carry out a guerrilla war against its successor.
The Soviets' last-minute effort to cobble together a coalition government in Kabul continued yesterday with discussions in Pakistan by Foreign Minister Eduard Shevardnadze. But officials privately admit they left the search for a real coalition until too late.
Moscow's worst-case scenario is a Kabul government dominated by fundamentalist leader Gulbuddin Hekmatyar. In the long run, they say, any Afghan government will see the desirability of good relations with its Russian neighbor. But they worry that in the short term, a Gulbuddin government would revive fundamentalist fervor in the Middle East.
Some officials also express concern at a possible fundamentalist spillover into the Soviet Muslim republics. They say that they will hit back hard at any Afghan attempt to foment unrest.
As Mr. Shevardnadze arrived in Islamabad, Soviet forces in Afghanistan were being rapidly drawn down. By yesterday about 1,000 Soviet troops were left in the Afghan capital. There were unofficial reports in Moscow that Kabul airport, the regime's last remaining lifeline to the outside world, would be handed over to Afghan authorities yesterday.
The largest remaining Soviet force - about 24,000 men - was concentrated the western air base of Shindand. They were also reportedly preparing to leave.
The pullout is being completed well ahead of the Feb. 15 deadline - something that Soviet analysts privately predicted in mid-December. An early withdrawal, they said, would enhance the security of departing troops, perhaps because harsh weather would impede guerrilla buildup along the exit route. But Soviet commanders are taking no chances: The military newspaper Krasnaya Zvezda said that the departing troops are being given 10 days' rations for the two-day trip.
Psychologically, the Soviets seem already to have withdrawn from Afghanistan. Press coverage now focuses almost completely on the pullout.
But the withdrawal may intensify the debate among Soviet intellectuals about the use of force to further political ends. The prevailing line in Moscow is that the 1979 Afghan invasion was a disastrous mistake based on little knowledge of the on-ground situation. But many observers still have difficulty admitting that the decision was totally wrong.
Vladimir Basov, an academic specialist on Afghanistan, said during a recent television discussion that, on one level, the intervention was justified. He fell back to the well-used analogy of a burning house. When your neighbor's house is on fire, you rush to help, he said. He was immediately savaged by Alexander Bovin, one of the most outspoken commentators on foreign affairs. ``Haven't we been firemen too often?'' Mr. Bovin asked. ``Do you remember Hungary in 1956, and Czechoslovakia in 1968? Haven't we offered too many fire services?''
But Moscow has more immediate concerns. One potential problem will arise if the PDPA retreats to an outlying province - perhaps Mazar-i-Sharif - and continues to fight a new regime. Some Soviet observers believe this is a strong possibility. One recently referred with some trepidation to a newly formed ``fanatical'' unit of PDPA members and elite Afghan troops. Guerrilla warfare by the PDPA could complicate Moscow's delicate task of stabilizing relations with a new government.
Western observers have recently spoken of a possible coup in Kabul by PDPA ``moderates'' keen to make a deal with the guerrillas. Moscow might well be relieved at such a development. The Soviets have been much more concerned about the possibility of a coup by hardliners.
The experiences of Saigon in 1975 and Manila in 1986 suggests, however, another possible outcome: demoralized and unpopular regimes do not always last until their adversaries can deal them the final blow. They collapse from within.