BEHIND THE TURMOIL of last week's rioting in Mecca lies a suprising and welcome fact: Saudi Arabia and much of the rest of the Moslem world are more stable than western analysts may imagine.

Consider the difference between last week's violence in Mecca and the events of 1979, when religious fanatics attempted to take over the Grand Mosque. At that time, Iranian broadcasts to the Islamic world claimed that the United States was attacking Mecca. These calumnies led directly to anti-American riots in several cities and the burning of the U.S. embassy in Pakistan. And there were fears that Saudi Arabia itself might be on the verge of collapse.

Eight years later, the Iranian line was much the same, but it provoked anti-American demonstrations mainly inside Iran itself. The latest Mecca crisis began when Iranian "pilgrims" suddenly led riotous demonstrations against the United States in the holy city a week ago. Saudi security forces attempted to control the demonstrations, and when the crowd got out of hand, hundreds of people were trampled. Ayatollah Khomeini then accused the United States and Saudi Arabia of "using premeditated means" to carry out a "dastardly attack" on innocent, unarmed Moslem pilgrims. But there was little response in the Islamic world, other than a prearranged demonstration by "relatives" of the victims in Tehran a few hours after the incident, before the victims themselves had even been identified.

The Mecca events illustrated the seriousness of Iran's challenge to Saudi Arabia. Since its revolution, Iran has used the annual pilgrimage to create demonstrations and disturbances in Mecca every year. The "innocent" Iranian pilgrims allowed to make the pilgrimage are in fact hand-picked by the regime. Considerable numbers are trained for disruptive demonstrations; virtually all are instructed to follow the lead of the demonstrators. The annual pilgrimage has thus become an annual confrontation between Iran's ambitions and Saudi tolerance. Last weekend's riot was merely the worst incident, but it was far from the first.

But the Mecca incident also provides an important reassurance about Saudi stability. The contrast with the 1979 seizure of the Grand Mosque by fanatics is stark:

The Saudi security forces' response in 1979 was ineffectual and panicky. Ultimately, outside help (reportedly including elite French forces) was required to assist in rescuing Islam's holiest shrine. Last weekend, in contrast, Saudi security forces dealt with the attempted uprising quickly, effectively and appropriately. The Saudis insist they didn't use firearms, but in any event, they did succeed in preventing the takeover of the mosque.

The Saudi government attempted in 1979 to cut off all news of the events in Mecca. This created an idealenvironment for the spread of wild and inaccurate rumors by Iran. The latest incident, by contrast, generated a speedy and effective Saudi response. Films of the Iranian pilgrims' provocations and of restrained security-force reactions were quickly made available to other Islamic governments and to the news media. Official representatives from 44 Moslem countries witnessed the bodies and attested that the dead had not been shot. Saudi news releases on the incident were forthright and surprisingly complete. Most Moslem countries expressed immediate solidarity with Saudi Arabia, reinforcing rather than weakening the role of the kingdom in the Islamic world.

The Saudi overreaction to the 1979 incident continued long afterward, and it contributed to international fears about Saudi stability. Indeed, during the early 1980s, Saudi internal-security forces vigorously monitored the behavior of Shia Moslems and other potential opponents. It's too early to predict how the Saudi government will cope with the aftershocks of last week's events, but so far there seems little of the paranoia of 1979, and an overreaction seems unlikely.

The contrast between 1979 and 1987 extends well beyond the reaction of Saudi Arabia, of course. It is noteworthy that this time there were no demonstrations of support for Iran anywhere in the Moslem world. Whether Shia or Sunni, none believed the Iranian propaganda, and most seemed to recognize the subversive responsibility of Iran for the incident. Within Saudi Arabia, which has its own sizable Shia community in the Eastern Province, there was not the slightest sign of identity with the miscreants in Mecca or the masters in Tehran.

The Saudi internal-security apparatus has become far more efficient and professional. As a result, there is less evidence today than a decade ago of two potentially dangerous cleavages in Saudi society: pro-Iranian sympathy among the Shia minority; and regional tension between the "Najdis" (the powerful Bedouin tribal families of the Riyadh area) and the "Hijazis" (the merchant families of the Red Sea coast).

The kingdom's Shia minority gets considerable attention from Saudi critics in the West, but the problem appears manageable for now. The Shia population is fairly small -- about 250,000 out of a total Saudi population of 7 million. What worries analysts is the fact that the Shias are located in the Eastern Province -- where the Saudi oil fields are -- and represent about 40 percent of the labor force there.

The Saudi security forces have tried hard in recent years to keep a vigilant eye on the Eastern Province, and pilgrims from there are watched carefully during the pilgrimage season. The government also has tried to improve the economic well-being of the Shia population by providing schools, hospitals and other amenities that were previously lacking in the region.

Some Saudis even see the recent decline in oil prices as a healthy development for stability within the kingdom. Austerity has encouraged greater efficiency in the Saudi economy, checked indiscrimate displays of wealth and reduced the opportunities for corruption. Moreover, the price decline has hit the richest Saudi merchants far more than it has affected the average Saudi. With lower oil prices and production, there are fewer expatriates, which in turn has meant a housing glut and a lower cost of living for most Saudis.

The sense of cohesion among well-to-do Saudis is also better than it was eight years ago, when tension between the Najdi Bedouins and the Hijazi merchants was a continuing problem. The reason for this improvement is that in key areas of Saudi business and political life -- such as the Air Force, the Royal Commission for Jubail and Yanbu and Aramco -- there has been a conscious effort to integrate Hijazis and Shias into the middle and upper ranks of the technocracy.

The Saudi military has been an object of concern to western analysts, who have wondered about its cohesion, effectiveness and political reliability. In recent years, the Saudi armed forces have given every appearance of stability. Tensions occasionally surface, but the military as a whole has been remarkably loyal to the government.

For all these reasons, last week's Mecca uprising proved to be an Iranian plot that misfired. In the wake of a string of successes, such a failure raises a hopeful portent. For the impact of earlier Iranian victories was worrisome. The Soviet Union is now negotiating with Iran like a superpower. And as we learned from the Iran-contra affair, the United States, too -- unable to achieve its goals in Lebanon, unable to secure the release of its hostages, unable to respond effectively to the growing wave of Iranian-sponsored terrorist attacks -- has also treated the Islamic republic with the deference normally due only a great power. Certainly, the regional states throughout the Middle East fear the designs and determination of the leaders in Tehran.

Americans should understand that the conflicts in the Gulf are not primarily religious. They are political -- a struggle for power and dominance in the region. Lacking conventional military striking power, Iran's leaders use other tools to exercise influence. They exploit regional resentment toward Israel. They manipulate the fear of the penetration of western social values that are seen as a threat to local traditions. And they use religious symbols to exploit deep-seated religious values.

Those who consider the Iranian regime "religious" must develop a tortuous logic to explain how the hajj, the holy pilgrimage, can be demeaned by political demonstrations. This is not extremism on behalf of religion; it is certainly not "fundamentalism"; it is power politics without scruple. As in the use of masses of children to fight the war with Iraq, as in its resort to terrorism, the Iranian regime is extremist in the sense that it recognizes no limits in acting to advance its own political interests.

While last week's Iranian provocation failed, we should perhaps ponder how different things might look in the region if Iraq should lose the Gulf war -- if, in other words, an Arab Islamic republic in Iraq were able to echo the noises coming from Iran. It is difficult to gauge the impact such a concerted propaganda campaign might have, particularly given the enormous size and power of these two countries against the small and relatively weak states of the Gulf. One must wonder whether this Arab echo of the Ayatollah would encourage Iranian sympathizers in Saudi Arabia and other Gulf states to act in support of the Iranian vision.

The Iranian assault on the traditions and institutions of the Gulf area -- and, as we have seen, the entire Middle East -- is still potent. Their long-term pressure against Kuwait is producing growing schisms within Kuwaiti society. Unlike Iraq, a large country where the government exerts substantial control over the population, Kuwait is a small and vulnerable state where a few terrorist attacks or well-placed explosions might lead to rapid disintegration of the country's infrastructure.

Saudi Arabia and the Gulf states have long sought and benefited from security cooperation with the United States. At the same time, the Gulf states have resisted too close a relationship with the United States, too encompassing an embrace. Since the most recent Iranian propaganda argues that Saudi Arabia got its "marching orders" from Washington to kill Moslems, the aloof Saudi position looks positively prescient. U.S. forces based in Saudi Arabia would certainly give credibility to the Iranian claim. Moreover, U.S. bases or forces would tend to impel many Saudis toward a choice between their Islamic and Saudi identities, a choice that would certainly be unhealthy for the region as well as for the kingdom and the United States.

The current American role in the Gulf raises the visibility and vulnerability of the United States in that increasingly troubled area. Without addressing in detail the issue of reflagging Kuwaiti tankers, it is clearly true that as long as the Iranians are targeting the West and using anti-western rhetoric, it is in America's interest to minimize the number of targets it must protect in the Gulf.

But the Iranian threats to Saudi stability and Gulf shipping can't be wished away, either. They are real, and so is the commonality of interest between the West and the moderate Arab states that are the principal targets of Iranian ambitions. Rather than reacting to these threats on a piecemeal basis, the United States and its Arab allies need an overall strategy. Both the Arabs and the Americans must deal with domestic political constraints. But these shouldn't prevent either side from taking steps that are clearly in their mutual interest.

Mazher Hameed, a Saudi political- and security-affairs analyst, is the author of "Arabia Imperilled."