MANAMA, BAHRAIN, JULY 31 -- Thousands of Iranian pilgrims demonstrated and clashed with Saudi riot police today near the Grand Mosque in the holy city of Mecca. Saudi officials said several people were killed in a stampede.

But Iran's official Islamic Republic News Agency (IRNA) reported that scores of Iranians were killed when police fired on demonstrators, and the Iranian Foreign Ministry summoned the Saudi charge d'affaires in Tehran to protest the incident.

From Mecca, the official Saudi Press Agency (SPA) reported that security forces managed to contain the rioters and restore order in the city, the birthplace of Islam.

{In Washington, an SPA dispatch said Saudi security forces intervened after "some Iranians burned a number of cars and injured several persons." The dispatch mentioned casualties, but no deaths. It quoted a source in the Saudi Arabian Interior Ministry as saying that security forces "will absolutely not compromise in performing their duties."}

The demonstration was staged at the urging of Ayatollah Ruhollah Khomeini, who in daily messages broadcast to the pilgrims has called on them to stage marches dubbed "Disavowal of the Pagans."

The broadcasts by Tehran radio were monitored in Nicosia, Cyprus.

The riot began when the Iranians took to the streets of Mecca around the vast mosque in a demonstration. An estimated 2.1 million Moslems from 64 countries are in Mecca for the pilgrimage.

Witnesses told The Associated Press that the demonstrators, chanting, "Death to America, Death to the Soviet Union, Death to Israel," overturned and burned cars, blocked intersections and burned effigies of President Reagan.

They also barred local residents from circulating in locations near the Kaaba, Islam's holiest shrine, the witnesses said.

IRNA said the incident was "believed to be a plot designed and carried out on the direct orders of the U.S. through its Saudi mercenaries." It said that "scores of innocent Iranian pilgrims were martyred and many others wounded."

Tehran radio claimed that the demonstration was attended by 155,000 Iranians making the pilgrimage to Mecca. The pilgrimage is required of all Moslems at least once if they can afford it, and today's events came four days before the centerpiece of the pilgrimage period, the Eid al Adha feast that begins Tuesday.

IRNA said Saudi police detained eight Iranians in Mecca yesterday without specifying the reason. It said they were released today after thousands of Iranians gathered in the area, shouting, "None but Allah, Down with the United States" and demanded the detainees' release.

Oil-rich Saudi Arabia, ruled by a conservative Sunni Moslem monarchy, is proud of its role as guardian of Moslem holy places and allows thousands of Iranians to make the pilgrimage annually.

In November 1979, about 250 armed followers of Seif Oteibi, an Arab Sunni Moslem extremist, occupied the mosque. After a two-week siege, Saudi troops regained control of the mosque, leaving more than 100 extremists, and scores of Saudi troops, dead.

Recently Iran's Shiite Moslem leaders have criticized Saudi Arabia for helping Iraq, Tehran's enemy in the 7-year-old Persian Gulf war, by selling oil on Baghdad's behalf.