he remains of Mohammad Reza Pahlavi, the disgraced and deposed shah of Iran, lie almost forgotten behind closed doors in the towering Rifai Mosque near Cairo's old citadel. But the ghost of his political career has suddenly risen to haunt his host, President Anwar Sadat, who, like the shah in the last years of his reign, finds himself pitted against militant fundamentalists seeking to use the power of Islam to topple his regime.

Since the sweeping wave of arrests of Moslem extremists here this month, everyone from ordinary Egyptians to Western diplomats and media commentators in Western Europe and America has begun to draw comparisons between Egypt and Iran.

Even the Egyptian leader has taken to doing it, if only to defend himself against critics who are dubbing him "shah number two" and warning of another debacle for American policy in the Middle East similar to the dramatic fall of the shah in early 1979.

Sadat appears certain of his people's support and the strength of Egypt's institutions. He has been quick to reassure his foreign backers, most notably the United States, that there is no chance of another Ayatollah Ruhollah Khomeini taking power in his Nile Valley nation, now a cornerstone of American military and political strategy in the Arab world.

"Don't fear that we shall have a Khomeini here," he told a press conference called after his massive crackdown to chide the foreign press for suggesting that he might become another shah.

At first glance, the sights and sounds of recent events here seem disturbingly similar to those that led to the shah's overthrow. Militant sheiks preaching against Sadat and his policies from the sanctity of their mosques; bearded, white-robed Moslem fundamentalists marching in the streets at the head of chanting crowds and big demonstrations on religious occasions in the main squares of Cairo. Even one of the main bugbears of the opposition here is the same as it was for demonstrators against the shah--Israel.

In addition, there was one popular sheik, Abdel Hamid Kishk, whose supporters had taken to taping his sermons on cassettes and peddling them all over the country for $1.50 each, just as Khomeini's followers did in Iran.

Sadat's legions of defenders here, chief among them most Western diplomats, are nonetheless quick to belittle any suggestion that there are more than superficial parallels between his and the shah's problems. Yet others, with no axe to grind, see at least some reflections here of Iran prior to the shah's ouster, though they also note important differences.

"There are some very alarming trends that might put Egypt in the same position," said one American professor who asked to remain anonymous in the wake of Sadat's crackdown. "But Egypt today, 1981, is not Iran in 1977. If it is, tell me who is next after Sadat."

Among the trends most often mentioned as similar to those in Iran contributing to the shah's downfall are the rise of Islamic fundamentalism, the attempt by the opposition to parlay religious fervor into political power, the use of the mosques as a base for attacking the government, and increasing social and economic tensions within Egyptian society stemming from a spurt of economic prosperity that has brought high inflation, an acute housing shortage and middle-class discontent.

Cairo University professor Ali Eddin Dessouki said, "Egypt has gone through some wrenching changes in the past decade. We have gone from Nasser's socialism to Sadat's 'open door' economic policy, from the Russians to the Americans and from the Arabs to the Israelis. It's all very confusing."

With these dramatic changes has come a heavy dose of what is generally labeled "Westernization," including a mass of imported consumer goods Egyptians have never seen or tasted before, a large influx of tourists, drinking, prostitution, gaudy nightclubs, a conspicuous display of wealth and a wide variety of American television programs, including the highly popular "Dallas."

"The Islamic resurgence is a protest against these kinds of Western manifestations," said Dessouki, who has just published a book in the United States on Islamic resurgence and the Arab world. "You have more and more Westernization and more and more Islamization."

Probably the most striking and visible sign of this Islamization is the recent trend among women here to don traditional clothes once again, including long, plain-colored robes, head scarves, gloves and full or half veils.

The latest fashion sweeping Cairo is all the more extraordinary since Egyptian women defiantly took off the veil 60 years ago and have long been regarded as among the most "liberated" anywhere in the Arab world.

Two years ago, few educated women in Cairo could be seen wearing traditional robes. Today, walking down Sharif Street, one of the main shopping streets in downtown Cairo, women in blue, white or gray robes are a common sight; probably one out of 10 women in the big cities, show some sign of following the trend.

A Western diplomat who served in Iran and is now here remarked that women took to wearing the traditional chador as a sign of protest against all that the shah and his attempt at rapid modernization stood for. The gesture became a harbinger of the political storm that was to engulf the shah but was not recognized as such at the time, the diplomat reminisced.

Here in Egypt, Dessouki sees the trend as a "statement of protest" directed against the whole Westernization of Egyptian society rather than a protest against Sadat's rule.

Whatever the mix of motives, a growing number of Egyptian women are rejecting the dominant Western style of public dress and in this manner apparently displaying both their faith and their displeasure.

Another shade of Iran visible here, and of far greater concern to some Western diplmats, is the tendency of Sadat, like the shah before him, to brook little contrary opinion, not only from outsiders but even his closest advisers. They fear that he may end by surrounding himself with yes men.

Analysts here are convinced that they have just seen a good example of what happens to an adviser who takes issue. In the latest Cabinet shuffle, Mansour Hassan, minister for presidential affairs and information and a rising star, was summarily fired. Prior to his dismissal, there were numerous reports that Hassan had counseled greater restraint in Sadat's massive crackdown on religious extremists and his critics, as well as his public dressing-down of the foreign press corps.

Yet, the same analysts tend to note as many dissimilarities, if not more, between Sadat and the shah, their respective political systems, the nature of the Moslem fundamentalist movements in the two countries and the temperament of the two societies.

Even one of Sadat's toughest foreign critics, British journalist David Hirst, who is about to publish a book on his regime, concedes that the two governments are "very different." He noted in an ABC television interview, which was confiscated by the Egyptian government, that there is "no grim police system" here comparable to the shah's hated SAVAK.

Among the many other differences is the history of Islamic fundamentalism here. As the birthplace of the Moslem Brotherhood, Egypt has gone through several cycles of Islamic resurgence and fundamentalist opposition activity, including terrorism and assassinations, since the early 1930s. The current one is not the first challenge to the political establishment, nor indeed the most serious, from Moslem religious quarters.

Since Sadat arrived on the political scene in 1952, alongside the late Gamal Abdel Nasser, as leaders of the Army cabal that overthrew the monarchy here, he has had to deal with at least three serious coup attempts by Moslem fanatics. These included the near assassination of Nasser in Alexandria in 1954 and an attack on the Army military academy in Cairo in 1974, which was allegedly the first step in a move to oust Sadat.

In reaction, Nasser, and later Sadat, took measures to suppress the Moslem Brotherhood and its radical offshoots, including the execution of some of their leaders. Despite these steps, Sadat has had a reputation for greater tolerance of the brotherhood and sympathy for its cause than Nasser did, using them at times to combat communist and leftist opposition to his regime.

Furthermore, unlike the shah, Sadat never turned his back on the Moslem ulema, the country's religious leaders, or tried to stem the tide of religious zeal sweeping Egypt. Instead, he reacted to the pressure by acceptance of the Islamic shari'a as one, if not the sole, basis of Egyptian law and established a shura (consultative) council in keeping with Islamic traditions of government.

Also, unlike the shah, he generally has lived a pious life. Sadat does not drink alcohol, attends the mosque regularly and has a habit of going into religious retreat during the whole of Ramadan, the Moslem month of fasting and prayer.

Another difference analysts point to is that between the structures of Shiism, the dominant sect of Islam in Iran, and those of Sunnism, the branch prevailing here. There is no hierarchy of religious leadership here as there is in Iran, and the closest thing to an ayatollah is the government-appointed sheik of the 1,000-year-old Al Azhar Mosque. Furthermore, there is no real independence of sheiks and mosques from the Egyptian state.

One of the potentially dangerous trends Sadat tried to stem in his latest crackdown was the attempt by the fundamentalists to set up an independent system of mosques, emirs, or princes, and secret societies. Local press reports said there were 1,500 such societies--that figure apparently included some Christian ones--and between 300,000 and 400,000 private mosques, which are now being put under state control.

Precisely how well organized and widespread the fundamentalists had become when Sadat struck early this month is far from clear. In a recent speech, the Egyptian leader estimated the membership in one organized network of Islamic student groups at only 7,000, although it seems their influence spread over a far larger number of students.

He accused them of using "terror" in the streets and on the campuses to impose their views, and he hinted that they were preparing to use armed force against his regime. They thought they could "imitate Khomeini" and come to power in the same manner, he said.

If this was their plan of action and Khomeini their inspiration, then perhaps Sadat was acting to prevent a repetition of Iranian history in his own country. Apparently he concluded that the lessons to be learned from the shah's own handling of his opposition was that an early show of force and massive crackdown were essential. All this strongly suggests, whether he likes to admit it or not, that Sadat is living in the shadow of the shah, at least when it comes to dealing with his Moslem fundamentalist opponents.