Saudi National Guard troops fought their way into Mecca's Great Mosque today and arrested most of the Moslem extremists who have occupied the shrine and have held scores of hostages for three days, the government announced.

Reliable sources said, however, that exchanges of gunfire between Saudi forces and holdouts inside the mosque continued into the evening and several dozen hostages remained under the control of the extremists.

Saudi Information Minister Mohammed Abdo Yamani said the battle would soon be over and promised the kingdom would "severely punish this group that has profaned the house of God in the full sense of the word, under the guise of Islam."

There were no reliable estimates of the number of casualties during the three-day standoff between the gunmen -- who declared one of their number inside the mosque the "mahdi," or final prophet -- and the Saudi troops who first surrounded the mosque, then shot their way inside. At least two Sadi security guards were believed to have been killed when the militants seized the shrine.

Witnesses and Saudi officials have estimated the number of gunmen that tookover Islam's holiest shrine in the initial battle Tuesday at from 100 to 200. The number of worshipers in the mosque at the time was not known, but unconfirmed reports spoke of as many as 1,000 people.

Prince Nayef, the Saudi interior minister, said no Iranian Shiites were involved in the mosque takeover, contrary to earlier reports from Arab sources in Tunis. But the action dramatized for this conservative Islamic monarchy the potential for trouble From A1 across the Persian Gulf region in the restive climate created by the Shiite Moslem revolution in nearby Iran and the rise in Moslem militancy it has promoted.

Yamani said most of the occupiers were Sadi Arabian nationals, although a "small number" of foreigners, whose nationality he declined to specify, also were involved. Other sources said they were Arabs and probably included some Yemenis from the more than a million who live in the kingdom and work in its booming oil economy.

Most of the gunmen were believed to belong to the relatively obscure Mahdist strain of Islam, which believes a "final prophet" or "enlightened one" will appear sometime before the end of the world to lead the Moslem faithful, knowledgeable sources said.

Although this belief is found among Shiite Moslems such as those in Iran, it also has arisen among some unsophisticated Saudis from the dominant Sunni sect, they added.

Several Saudi Mahdist leaders have been the source of earlier agitation, informed officials said, and Saudi security police have in the past closely monitored their activities.

The Interior Ministry reported yesterday that one of the gunmen had been presented to the hostages as the "final prophet" soon after the takeover, which began during dawn prayers.

The early-morning takeover seemed to be an attempt to conform to one Mahdist prophecy that says the Mahdi will be proclaimed at dawn prayers at the Great Mosque and that fighting in the streets of Mecca will accompany his coming. The attack came at dawn on the first day of the new 15th Islamic century.

The Mahdist belief traditionally has been disdained by Saudi Arabia's dodminant Wahhabi brand of Sunni Islam, which follows a strict interpretation that allows little room for doctrine not specifically contained in the Koran. In addition, Saudi law and customs revolve around orthodox Moslem beliefs.

"This country is built on the basis of the Islamic code, which spreads confidence and trust among members of the nation and its Islamic rule," Yamani said.

It reamins unclear precisely what touched off the mosque takeover, however, and Saudi officials continued to turn away queries. The official statements from Nayef and Yamani stressed the religious aspects of the incident, suggesting that fanaticism by the little-known Mahdist group was the only motive behind it.

"Maybe they just made up their own minds," said a foreign analyst grooping for an explanantion. "Maybe all the fevor of the Shiites in Iran, that may have been all they needed to try and exert their faith."

Whatever their motives, the gunmen appeared well armed and were supplied with enough ammunition to resist the Saudi security forces for three days. This seemed to indicate enough coordination to mount a surprise attack and get the munitions inside.

Saudi authorities repeatedly have stresed that they were retaking the shrine slowly and extremely cautiously to avoid unnecessary bloodshed or damage to the sacred structure.

"We could reasonably have struck with force at any moment," Yamani said. "But the competent security forces were anxious to treat this problem with all wisdom and care for the innocent Moslem lives inside the mosque, who had no guilt and no link to this affair."

Yamani's statement, read over the state radio, underlined the distress of Saudi Arabia's royal rulers at seeing the mosque -- the holiest site in Islam -- defiled by gunmen invoking Moslem beliefs. Repeating earlier Saudi assertions, Yamani emphasized that the attackers belonged to "a group that has deviated frm the Islamic religion."

The Saudi operation was being carried out mostly by troops from the 35,000 man National Guard, the chief internal security force. Prince Abdullah, the guard commander and one of the most powerful men in the kingdom, was reported to have returned yesterday from a private visit to Morocco to help supervise the troops.

Responding to a request from Washington, the interior minister, Nayef, declared specifically that the United States had no connection with the incident. Agitation over charges broadcast by Iranian radio that Americans were behind the occupation helped infuriate Moslem crowds that attacked the U.S. Embassy in Pakistan and mounted demonstrations in Turkey, India and Bangladesh.

"The incident is totally removed from any political motives," Nayef said in a statement also broadcast over the Saudi radio.

His declaration demonstrated concern among Saudi officials about reports abroad suggesting the occupation could be connected with an Iranian-style popular movement. This is a particularly offensive notion to the Saudi rulers, one of the world's few remaining absolute royal families.

The hostages at the mosque were believed to include a number of foreign Moslems. Foreigners often visit the mosque to pray and many have not yet left after the annual hajj, or pilgrimage, that ended last week. Saudi officials estimate about 2 million visitors entered the kingdom for this year's observances. Departing pilgrims still can be seen with their bundles and suitcases lying around Jeddah Airport waiting for flights home.

It is partly because the royal family is entrusted with protecting Islam's holy sites that the takeover is particularly galling. There have been no indications whether the mosque has been damaged by gunfire. But in any case, the incident has generated publicity around the world about gun battles in the most sacred site in Islam.

As a result, government officials were reluctant to disclose any information about the situation and closed off communication with the rest of the world for 15 hours Tuesday. Since then, they have revealed only what is necessary to keep up with reports from abroad, correcting those they say are erroneous.