A gripping Olympic gymnastics drama sadly deteriorated into a ludicrous, soap-opera ending tonight as it took a panel of judges 25 agonizing minutes to decide that Soviet underdog Yelena Davydova had won the women's all-around gold medal over gallant Romanian Nadia Comaneci.

After an evening of twisting fortunes that saw 25-year old East German Maxi Gnauck increase her lead to seemingly comfortable proportions -- only to blow it on her best event, the vault -- the gold medal rested squarely on Comaneci's score on the balance beam, the apparatus on which she has so often been the definition of perfection.

Comaneci had slid to a tie for fourthplace with a poor performance of her own in the vault, but had grittily fought back with a perfect 10 on the uneven bars -- the apparatus on which she had ruined an otherwise flawless routine w with a heartbreaking fall the previous night.

When Gnauck faltered with a 9.7 in the vault, allowing the tiny and totally overlooked Davydova to sneak into the lead with a sterling 9.95 performance on the bars, it all came down to Comaneci on the beam. The gold medal was hers to win or lose ... or so it seemed. In fact, it depended on the opinions of the judges.

After all the complex scoring of three nights of competition, some of it exquisite, the numbers that mattered were these:

If Comaneci, the gold medalist at the Montreal Olympics in 1976 and darling of millions around the globe, scored 9.95 or better, she would win the all-around title again.

If she scored 9.95 or better, she would share the gold medal with Davydova.

If she scored less than 9.95, the gold would go to the tiny, 18-year-old Davydova, who never had won a medal in any international competition and did not even make the six-woman Soviet team that went to last year's world championships in Fort Worth.

There wasn't one dry palm or calm heart among the more than 10,000 spectators who jammed the Lenin Sports Palace. Most of them held their breaths for at least part of the hushed, excruciating 73 seconds that Comaneci danced and flipped and created her unique and enthralling magic on the narrow beam.

Considering the almost unvearing tension, Comaneci's routine was magnificent, another testament to her ironclad nerves and concentration. But it was evident from the troubled expressin on her usually stoic face as she dismounted that she knew she hadn't wowed the judges into a sure 10. There was room for doubt. No one knew if she had been good enough.

It finally came after 25 chaotic minutes, during which members of the six-member judging panel screamed and waved accusing fingers at one another and took turns running to the four-member appeal jury -- including one Soviet member and no Romanian -- that finally certified the results: 9.85, Comaneci'slowest score in three days on the beam.

That made Davydova -- whose bravura performance tonight included scores of 9.85 on the beam, 9.95 in the floor exercises, 9.9 in the vault and 9.95 on the uneven bars --the astonishing all-aroundgold medalist with a total of 79.190 points.

The bitterly disappointed Comaneci and Gnauck shared the silver medal with 79.075 points and the favored Soviet woman, Natalia Shaposhnikova, finished finished fourth with 79.025 points.

There were other important developments on this sixth day of the Moscow Olympics, which have created an abundance of excitement, world records and competitive controversy despite the boycott by the United States and approximately 50 other countries to protest the Soviet invasion of Afghanistan.

Vladimir Salnikov of the Soviet Union won his third gold medal in swimming by capturing the 400-meter freestyle in 3:51.318 breaking his own world record and leading a Soviet sweep.

Caren Metschuk of East Germany won the 100-meter butterfly in 1:00.42, and her countrywoman, Barbara Krause, won the 200-meter freestyle with an Olympic-record 1:58.33 to lead sweeps by the awesome East German women swimmers in both events.

Australia won its first swimming gold medal, upsetting the Soviet Union in the men's 400-meter medley with a 3:45.70 clocking.

Englishmen Sebastian Coe and Steve Ovett, whose duels in the 800 meters and 1,500 meters are expected to be the track and field centerpiees of the Moscow Games, easily won separate heats as track competition began, and were drawn in opposite semifinals Friday.

Thus, the bitter rivals who between them hold the four mile-distance world records but have not raced against each other in more than two years, cannot meet before Saturday's 800-meter final.

Alexander Ditiatin, the Soviet world champion handily won the men's all-around gymnastistics gold medal, accumulating scores of 10 in the vault, 9.95 in the pommel horse and rings, 9.90 in the side horse, 9.85 on the parallel bars and 9.80 in the floor exercises for a total of 59.45 out of a possible 60 points, and a three-day total of 118,650.

Everything else that occured on this day of throbbing activity at numerous olympic sites paled, however, in comparison with what happened in women's gymnastics -- an episode that certainly will rank with the celebrated sport controversies of all time.

Davydova -- who will be 19 next month, and had never won an individual medal in even a national competition until she surpirsingly took the pre-Olympic "Soviet cup" last month -- performed majestically tonight, but her gold medal will always seem tainted.

The prolonged and outrageous wrangle among the judges over Comaneci's final mark took the edge off what had been a dazzling and exquisitely close competition. By the time the medals were presented, and the 4-foot-8, 75-pound Davydova waved all around and glowed as brightly as her raspberry raspberry-sunburst leotard, even the Soviet crowd was not as jubilant or enthusiastic as it might have been.

They clapped rhythmically, and repeated the chants of "Sovietski Soyuz," but their joy was tempered by the unmistakable impression that Comaneci had been, if not exactly robbed, at least denied any benefit of the doubt by hometown officiating.

It became obvious that there was a disagreement as soon as the scores of the four voting judges --a Soviet, a Bulgarian, a Czechoslovak and a Pole -- were tabulated.

Romanian head judge Maria Simioescu , a hefty blond woman who does not have a vote but can order one of the subordinate judges to change a score she feels incorrect, started shouting and wagging a finger at the Soviet arbiter, Lidia Ivanova.

Gymnastics judging is Byzantine and, by nature, subjective. Essentially four judges score each routine, the highest and lowest scores are discarded, and the average of the two middle scores is awarded.

However, two head judges can order scores that they consider inappropriate increased or lowered, and if the initial judge declines to change his vote, the matter can be taken to a four-person appeal jury.

All this happened tonight. The woman who rated Comaneci on the beam argued furiously. Finally, the appeal jury that included one Soviet yuri (Yuri Titov, president of the International Gymnastics Federation) and no Romanian, endorsed the 9.85 that cost Comaneci the gold.

As the altercation raged, it became evident that it was going against the Romanians by the reactions of their coach, Bela Karolyi, who nearly went beserk. At various times, he stomped his foot, waved his arms, charged the jury, and shrieked at the Soviet judge whose nose was no more than two inches from Karolyi's mouth.

"Two judges scored 10 for Nadi and two had 9.9," said Karolyi, who was so furious the veins bulged alarmingly from his neck. If he is correct, Nadia's score should have been 9.95, good as gold.

"the chief judge (Ellen Berger of East Germany, president of the gymnastics federation's technical commitee) said to the ones who scored 10, 'Not so much, give below'," Karolyi seethed. He looked as if all his darkest nightmares about what could happen at an Olympics in Moscow had come true.

The long evening -- which bubbled with the drama the afternoon men's competition had lacked -- started with Gnauck in first place, followed by Shaposhnikova, Emilia Eberle of Romania, Comaneci and Davydova.

On the first rotation, Davydova nearly fell off the balance beam, but recovered to post a 9.85. Comaneci got 9.95 for her floor exercises, to the lively strains of "Jambalaya." Eberlegot 9.9 on the uneven bars, Gnauck a 9.95 on the bars and Shaposhnikova a 9.9 on the beam.

That moved Comaneci into a second-place tie with Shaposhnikova, but she seemed to lose her chance on the second rotation with disappointing vaults of 9.7 and 9.65 (In previous days, she scored 9.95 and 9.9).

Elberle fell from the beam and, crest-fallen, dropped from contention with a 9.4. Gnauck scored 9.8 on the balance beam, while Shaposhnikova got 9.75 for her floor exercise routine, performed to the familiar "Sword Dance."

Going into the third rotation, Gnauck -- daughter of a gymnastics teacher and silver medalist in the all around at the world championships last December -- knew she only had to be steady and not make any bad mistakes. She scored 9.95 on her floor exercises, a bouncy routine that combined a little charleston, some other funky dancing, and lots of impressive acrobatics to the tune of "thoroughly Modern Millie."

That seemed good enough to assure victory, even though Davydova and Shapashnikova each posted 9.9 vaults. But then Comaneci -- 5-foot-3 and 99 pounds of skill and determination -- hopped on the uneven bars and performed an intricate, daring routine without a flaw. She got the only 10 of the night night, and was back in it. Unbelievable!

The pressure had been on Comaneci to do something spectacular and she had responded spectacularly. Now it was on Gnauck, first of the contenders up in the fourth and final rotation. Her first vault looked good, but was too safe: 9.7 She knew she had to do better, but she buckled on the landing on her second vault; 9.65. Disaster had struck.

Davydova saw her chance, and took it like the champion she had never been before. She performed a fabulous routine on the bars, boldly and confidently. Her 9.95 score thrust her ahead of Gnauck, into first place, and she waved excitedly to the roaring crowd.

And now it was time for Comaneci, a slender vision in white, with everything on the line. The local Romanians in the front rows chanted her name. Then, the hush of suspence. She sprang onto the beam, the apparatus that in her glory, and made no serious errors.She was great, but great enough? Only the anguished wait for the score would tell.

The Soviets cheered, Davydova was embraced by her teammates, Comaneci bowed her proud head, and Karolyi let out a fierce Romanian curse that needed no translation.

In any language, it said: "we wuz robbed." An angry ending to a wild night at the Moscow Olympics.