Thanks largely to Russian President Boris N. Yeltsin, Mikhail S. Gorbachev has been restored as the titular head of a disintegrating nuclear superpower. He and the man who saved his job and perhaps his life now face the daunting problem of patching together a functioning government.

Mr. Gorbachev and Mr. Yeltsin, who are scheduled to meet today to talk of a "government of national trust," must move swiftly and in close cooperation to build credible authority in Moscow. Otherwise the failed coup may open a period of dangerous uncertainty and drift, a vacuum of constitutional power that could be filled by emboldened, embittered crowds, renegade soldiers or other uncontrollable forces emerging from the euphoria of victory.

The first question facing Mr. Gorbachev: Whom can he trust? Until Sunday, the coup leaders the Soviet president bitterly denounced yesterday as "reactionary forces" were his closest aides and associates. The coup had the enthusiastic backing of Mr. Gorbachev's own John Sununu, chief of staff Valery I. Boldin, and the head of the KGB's Kremlin guard, Lt. Gen. Yuri Plekhanov, both of whom were dismissed yesterday.

The coup was vocally endorsed at an expanded Cabinet meeting Monday by more than two dozen government ministers -- virtually all still on duty. Top officials of the Communist Party Mr. Gorbachev still heads first prepared a statement backing the coup, then, as it fell apart, denounced it in high-minded language. Many more top state and party officials silently acquiesced in Mr. Gorbachev's removal or diplomatically dropped from sight for a few days to avoid taking sides in the three-day putsch that fizzled Wednesday.

The second question for the Soviet president: Given his track record in previous personnel appointments and his own minimal popularity, will the public accept his choices and pay attention to their commands? A casual remark from Mr. Yeltsin could instantly undermine Mr. Gorbachev's orders or shatter his appointees' credibility. With authority shifting swiftly and decisively from the central government to the republics, first of all the Russian Federation, Mr. Yeltsin would appear to have little reason to bolster the despised "center."

Recognizing the danger of a power vacuum, Mr. Yeltsin stepped beyond the legal bounds of his authority as the coup crumbled, asserting power over all Soviet government agencies and military units on Russian territory and dismissing the head of Soviet television and radio. Those steps were universally applauded, notably by Mr. Gorbachev, as necessary under the extraordinary circumstances of the coup.

But should Mr. Yeltsin politely cede all control of the military back to Mr. Gorbachev, the constitutional commander in chief, and to the army brass who seem to have hesitated for many hours over whether to blow away the Russian leader and his followers? If economic aid begins to flow from shaken Western leaders, should Mr. Yeltsin stand by and watch it go to the Soviet government whose bosses organized the coup?

What becomes of the Soviet parliament, which failed to move against the coup, and particularly its chairman, Anatoly I. Lukyanov, whose silence about the arrest of his old law-school classmate, Mr. Gorbachev, was telling. Mr. Yeltsin, with his usual bluntness, denounced Mr. Lukyanov yesterday as "chief ideologue of the junta."

Analysts of Mr. Lukyanov's career long ago detected evidence of close ties to the KGB, but it was unclear whether Mr. Yeltsin was criticizing the parliamentary chief's politics or charging him with treason. Should Mr. Lukyanov be patted on the back for not publicly joining the junta, or reprimanded, or arrested? Who decides?

For that matter, what now happens to the KGB? For more than two years, prominent Soviet democrats have declared that the huge secret police and spy agency is incapable of reform and must be disbanded. Mr. Gorbachev, much beholden to the KGB for his rise to power, chose instead to appoint as chief in late 1988 an ostensible liberal, associated with espionage and not internal repression. He gave him a mandate to shake up the feared institution.

The new man vigorously endorsed glasnost, created a KGB public relations office, reorganized the department that previously had persecuted dissidents and forged a new role for the KGB in fighting organized crime and "economic sabotage." Then, after becoming more and more openly critical of reform, the KGB chief, Vladimir A. Kryuchkov, helped organize this week's coup.

In what may rank as the most laughable denial of complicity in the coup -- though that is fast becoming a crowded field -- the collegium of the KGB yesterday issued a statement: "The KGB of the U.S.S.R. has nothing to do with these anti-constitutional actions," and Mr. Kryuchkov's colleagues "feel deeply upset by the fact that their honor was besmirched" by his involvement.

Mr. Gorbachev appeared ready yesterday to accept such embarrassing statements at face value. He appointed Leonid V. Shebarshin, another career intelligence officer, to replace Mr. Kryuchkov, making no mention of any need to disband or reorganize the KGB.

The citizens seem to have a different view. In what may be only the first taste of a more aggressive street politics in the transformed Soviet Union, angry Russians tried to topple the statue of Felix Dzerzhinsky, first head of the Soviet secret police, from its pedestal in front of KGB headquarters. When they failed, Moscow officials obliged with the cranes necessary to finish the job.