MOSCOW, MAY 31 -- Kremlin leader Mikhail Gorbachev is using a flagrant violation of Soviet security to launch a Defense Ministry purge and seal his control over the powerful Soviet military in a bold play for power that also runs the risk of destabilizing his regime, western diplomats said here today.

When a young West German flew through the Soviet Union's massive air defense system and landed his single-engine Cessna plane near the Kremlin Thursday, he inadvertently eased the ouster yesterday of Defense Minister Sergei Sokolov and one of his deputies, the commander of Soviet air defenses, by testing the ministry's security standards.

By immediately appointing as Sokolov's replacement Gen. Dimitri T. Yazov, a military official with experience in personnel policy but otherwise of relatively low rank, the ruling Politburo also signaled an intention to revamp the military and buttress control over it. Yazov is a relatively obscure military figure who is subject to control from Kremlin leaders.

In announcing Yazov's appointment yesterday, the Politburo "emphasized again the fundamental importance of the task of resolutely enhancing the level of combat preparedness and discipline of the armed forces," said a statement released yesterday by the official Tass news agency.

But in a country where the military is considered one of three pillars of power -- alongside the political leadership and state security -- the military shake-up is widely viewed here as Gorbachev's boldest reach yet at the reins of power.

The reason, according to western diplomatic assessments here, is that Gorbachev's own position is not yet secure enough to consolidate control fully over the military, with its record of wobbly support for some of the Kremlin leader's policies.

Gorbachev's program of broad economic and political reforms has met with resistance in the entrenched bureaucracy and recent criticism in some official publications. It is due to come under review in three weeks, when the Central Committee is to meet.

The sudden ouster of Sokolov and Alexander Koldunov, the commander of antiaircraft defense forces, and public upbraiding of the military both in a Tass dispatch and on national television, signals an about-face in the Gorbachev leadership's treatment of the military, which has so far been marked by compromise.

After military criticism of the outcome of the 1985 U.S.-Soviet summit in Geneva, for instance, the Kremlin adopted a cooler stance toward Washington.

After behind-the-scenes grousing among some military officials about the Soviet Union's unilateral nuclear-test moratorium began to emerge publicly, the Kremlin eventually ended the moratorium.

Even Soviet arms-control compromises appear to be packaged with concessions to the military. On the eve of a Gorbachev announcement that Moscow would break up its package of proposals and push for a separate deal on intermediate-range missiles, the Soviet Union exploded its first nuclear device in 19 months.

If the traditional balance of interests that is usually struck by the Soviet political and military leadership is upset, the military could eventually lash back, western diplomats said.

"At a time when Gorbachev is carefully building a consensus of support for his policies," one diplomat said, "Gorbachev is probably playing a risky game in alienating the military."

Gorbachev's strongest case for a military shake-up is the ministry's handling of the case of 19-year-old Mathias Rust, a West German pilot who flew to Moscow from Helsinki on Thursday, avoiding Soviet defenses and eventually taxiing his plane right up to the Kremlin wall in Red Square.

But the violation of Soviet airspace could just as easily be used to demonstrate the failure of Gorbachev's attempts to bring greater discipline to key Soviet ministries, one western diplomat said. "It could be used against him," the diplomat added.

Rust, still under investigation in Soviet custody, will be allowed a visit from West German officials early this week, a West German Embassy spokesman said today.

So far, the military has adapted slowly to Gorbachev's calls for reform, according to various official Soviet media reports. While articles in the Communist Party organ Pravda and other official publications have documented cases of corruption and lax discipline in the military, Sokolov's public calls for reform within the Defense Ministry were limited to a single speech, given two years after Gorbachev came to power and publicized in the military newspaper Red Star last March.

At the same time, the Gorbachev-led political leadership has appeared to have more control over the military than have previous Soviet administrations.

Sokolov, 75, never reached full Politburo status, for example, breaking a practice of appointing defense ministers to the ruling body that dates back to the early 1970s.

Yazov, 64, is a candidate member of the Central Committee, the first Soviet defense minister in memory not to have full Central Committee membership.

In his latest post, Yazov was deputy defense minister in charge of personnel.

In what appears to be an immediate effort to show support for Gorbachev's action, the offical news agency Tass today, in a highly unusual move, quoted remarks made in Washington yesterday about the incident by former White House national security adviser Zbigniew Brzezinski.

In those remarks, Brzezinski said, "The Soviets have done what the American high command and political leadership have not had the guts to do." The former Carter administration aide cited the loss of U.S. Marines in Beirut in 1983, the recent Marine guard scandal in Moscow and the attack on the USS Stark in the Persian Gulf as examples of failures in which no one was fired.

In addition, the newspaper of the Soviet armed forces reported today that some Soviet military officers had not adapted well to Gorbachev's call for reform. "Unfortunately, inspection has shown that the necessary reconstruction in thinking and work styles has not yet occurred among many officers, generals and admirals in the solution of this priority task."

The Reuter news agency reported the following from Hamburg, West Germany:

Although Rust may be tried for violating Soviet airspace, he likely will be allowed to return home soon -- a gesture of thanks from Moscow for pointing out the gaps in its air defenses -- the head of the Soviet press agency Novosti was quoted as saying in a West German newspaper interview.

"For one thing, we will thank him for pointing out the gaps," Valentin Falin, a former Soviet ambassador to West Germany and a confidant of Gorbachev, told the Hamburg Morgenpost newspaper.

"It could be that he will be put on trial," Falin said, adding, "but I reckon the young man will see his parents and friends again soon."