ULAN BATOR, Mongolia— In a makeshift temple at the foot of a rocky cliff in the Gobi Desert, four aged lamas in saffron robes sat cross-legged on carpets before a shrine to Buddha. They were fasting, meditating in silence and perusing sacred texts of Tibetan Buddhism.

Outside under a harsh sun lay the crumbling mud-brick ruins of the Ulgii Khiid Monastery, which once held more than a thousand monks. It had been sacked by the repressive Communist Government that ruled Mongolia for 70 years, a Government that destroyed more than 700 monasteries in the 1930's, burning books and executing thousands of lamas.

Now some surviving lamas are returning to occupy Ulgii Khiid and several dozen other monasteries. They live and worship in yurts, the customary dome-shaped dwellings of Mongolian nomads. They are teaching younger men to be monks and making plans to rebuild the temples. Resurging Nationalism

The scene of religious revival amid revolution's ruins illustrates the extraordinary changes under way in Mongolia. In yet another reverberation from the collapsing Soviet empire, the dictatorship tied to Moscow was ousted in March 1990 and replaced with a more reform-mined Communist Government and a Parliament that includes increasingly assertive democratic opposition parties.

With that new political freedom has come a resurgence of Mongolian nationalism.

One of its most fundamental expressions is the official and popular support for Buddhism, the traditional religion of Mongolians for centuries.

In an interview in his private reception room at the Gandan Monastery here, the Khama Lama, the country's ranking Buddhist cleric, said, "This movement is very strong, not only among Buddhists but all people."

Other religious leaders, officials, intellectuals and diplomats agreed. Although few Mongolians may have a deep knowledge or belief in Buddhism, they said, anything from the pre-Soviet days is encouraged and celebrated.

That goes also for Genghis Khan, the legendary 13th-century warrior who united the Mongol tribes and set out with the Golden Horde to conquer much of Eurasia. The empire controlled by him and his immediate successors included China and Russia and extended all the way to Hungary.

Since Communists came to power in a revolution here in 1921, the Soviet Union had tried to suppress the name and memory of Genghis Khan, in part because no national hero could be allowed to eclipse Lenin but also because of residual embarrassment over being one of the conqueror's victims. But now Genghis Khan rides again.

Within months of the fall of the Soviet-backed Government last year, Mongolian scholars convened an international conference to commemorate the 750th anniversary of "The Secret History of the Mongols," the epic describing the glory days of Mongolian power and influence.

In a message to the conference, President Punsalmaagiyn Ochirbat endorsed the rehabilitation of the national hero and spoke of the importance of "The Secret History" for "the renewal of the Mongolian society, consolidating of their national integrity and social progress and for the restoration and development of their historical and cultural heritages." Statue of Stalin Removed

At a diplomatic reception a few months ago, Mr. Ochirbat came up to an American military officer and congratulated him on the victory in the Persian Gulf war.

"Our countries now have one thing in common," he said. "We both have conquered Baghdad."

A statue of Stalin in the capital is gone, and billboards bearing Lenin's likeness have been painted over. But the image of Genghis Khan is everywhere, on banners at a trade fair and postcards and in souvenir shops. A vodka is named for him, and a local rock group sings his praises.

A Japanese-Mongolian expedition is spending its second summer in the nearby mountains searching for Genghis Khan's grave. If it is found, a museum will be built at the site.

Dr. Shagdaryn Bira, secretary general of the International Association for Mongol Studies and a member of the Mongolian Academy of Sciences, said the expedition had found several hundred tombs, including some from the 13th century, but not the one they were looking for.

"I'm against making Genghis Khan a demigod," Dr. Bira said. "He was neither a devil nor a god. He was a man."

Even so, Dr. Bira said, efforts were being made to enlist international support for archeological excavations at Khara-Khorum, Genghis Khan's capital. The ruins, west of Ulan Bator, are a regular tourist stop. But research there was suspended years ago, when Mongolians were discouraged from studying their early history, and so the country has a shortage of archeologists.

Officials of the Academy of Sciences, reaching out for contacts with the West, are capitalizing on their paramount scientific asset: dinosaur remains. A group of French and Italian paleontologists arrived in early July to examine the rich fossil beds of the Gobi. Paleontologists from the American Museum of Natural History in New York, working with Mongolians, have begun a planned three-year campaign of fossil hunting. Found Monastery Ruins

It was when the members of the American-Mongolian expedition were crossing the broad, desolate landscape between the towns of Saynshand and Dalan Dzadagad that they found the monastery ruins.