Saudi Arabia said it decided to break relations with Iran because of a riot by Iranians in Mecca, a raid on the Saudi Embassy in Tehran and Iranian attacks on commercial shipping in the Persian Gulf.

The Saudi government's announcement Tuesday was in a statement broadcast by state-run television and distributed by the official Saudi Press Agency. Saudi Arabia ordered all Iranian diplomats to leave the kingdom within a week.A memorandum about the decision was handed to the Iranian charge d'affaires in Riyadh, the news agency reported. There was no immediate public comment from Ayatollah Ruhollah Khomeini's revolutionary regime.

The Saudi statement, translated by The Associated Press, said King Fadh's government had exercised "self-restraint and prudence" and had sought to normalize relations, despite Iranian "terrorism and subversion."

"But the kingdom's positive stance gained no response whatever from the Iranian side, which persisted in perpetrating hostile practices," it said.

"Therefore, the government of Saudi Arabia decided to break its ties with the Islamic Republic of

Iran and asked all personnel of the Iranian Embassy in Riyadh and consulate general in Jiddah to leave the kingdom within a week," the statement said.

Iranian speedboats attacked a Saudi-owned tanker in the Strait of Hormuz on Sunday just hours after President Reagan warned Iran to stay clear of neutral ships. Hormuz is the narrow gateway to the gulf at the waterway's southern end.

Reagan's warning to Iran came after the U.S. Navy sank or disabled six Iranian naval vessels in battles in the Persian Gulf. The clashes occurred after the Navy destroyed two Iranian offshore oil facilities to retaliate for a mine explosion in the gulf on April 14 that damaged a Navy frigate and wounded 10 American sailors. The United States said Iran sowed the mine.

Iran, which has been at war with Iraq since September 1980, routinely raids commercial ships in the gulf to retaliate for Iraqi attacks on Iranian vessels. Iraq's attacks on ships owned by or doing business with Iran are aimed at cutting Iran's oil revenues, which help finance the war.