DHAHRAN, SAUDI ARABIA, NOV. 2 -- Saudi Arabia and Iran, bitter rivals in a decade-long competition for leadership of the world's Moslems, are holding high-level talks aimed at renewing diplomatic relations, according to Saudi officials.

No date has been set for resuming ties. But a recent visit to Tehran by a senior Saudi Foreign Ministry official -- the first such visit since relations were broken off in 1988 -- was aimed at resolving differences so that relations can be restored, the officials said.

Iran and Saudi Arabia are the two most powerful neighbors of Iraq in the Persian Gulf and the anticipated rapprochement of these two major oil producers, who were exchanging harsh attacks in the media only a few months ago, is an illustration of the shifts in regional alliances set off by Iraq's conquest of Kuwait.

It is also an example of the political and economic gains that Iran is reaping from the three-month-old gulf crisis, which could eventually see Tehran emerge with greater regional influence, diplomats and experts said.

"What Iraq has ironically done is set up a situation for Iran to reemerge as a major power in the gulf," said Augustus Richard Norton, a Middle East expert at New York's International Peace Academy.

Since Iraq's Aug. 2 seizure of Kuwait, Iran has won a measure of respectability for complying with the United Nations sanctions against Iraq and has enjoyed windfall profits from higher oil prices, Norton said. Tehran also has improved its ties with other gulf states and restored diplomatic relations with Britain after an 18-month break.

In addition, Iraq, under pressure from the U.N. sanctions and the U.S.-led troop buildup in the gulf, capitulated in August to Iranian terms for formally ending their 1980-88 war.

"Early on, our assessment was that Iran had a big opportunity to improve its image by sticking to the sanctions," said one European diplomat in Saudi Arabia. "So far, they have played their cards pretty well and are coming out on top."

A spokesman at the Iranian mission to the United Nations said Iran and Saudi Arabia are having a "dialogue" to resolve the "limitations" put on Iranian pilgrims making the annual hajj, or pilgrimage, to Mecca. That was the only topic under discussion as far as he knew, the spokesman said.

But the Tehran Times, which usually reflects the thinking of Iranian President Ali Akbar Hashemi Rafsanjani, raised the issue of renewing diplomatic relations with Saudi Arabia in an editorial earlier this week. "Full normalization of Irano-Saudi relations will of course require a long time," said the daily. "However, it should be noted that . . . achievement of a 'regional security plan,' in which the security of the region would be the responsibility of the regional states, requires good relations at least between the important countries in the Persian Gulf."

After the 1979 Iranian revolution, relations between Saudi Arabia and Iran soured as Tehran sought to export its militant brand of Shiite Islam to the Arabian Peninsula, which is dominated by the more conservative Sunni branch of Islam. Tehran also challenged Saudi Arabia's guardianship of Islam's holy cities, Mecca and Medina, saying the Saudi royal leaders were unfit for that role. Relations further deteriorated when Saudi Arabia supported Iraq in its war against Iran.

Although Riyadh accused Iran of financing anti-Saudi sabotage and terrorist activities, it did not sever relations until April 1988, after 400 pilgrims, most of them Iranians, died in clashes between protesters and Saudi security forces during the 1987 hajj.

The Saudis, who are seeking to maintain the international coalition aimed at isolating Iraqi President Saddam Hussein, appear eager to renew ties with Tehran in part to offset the recent improvement in Iranian-Iraqi relations, analysts said.

"We don't want Iraq and Iran to be allied," said one Saudi diplomat. "Because if that happens, it will be disaster for the region." Riyadh would like to see ties resumed "as soon as possible," he said.

The Saudi foreign minister, Prince Saud Faisal, and his Iranian counterpart, Ali Akbar Velayati, agreed to renew ties "in principle" during a series of meetings in September while both were in New York attending the U.N. General Assembly, Saudi officials said.

Last weekend, the Saudi deputy foreign minister for political affairs, Abdul Rahman Mansouri, flew to Tehran for two days of negotiations on obstacles to resuming ties. "It's not a political issue, it's a religious issue that has to be settled," said one Foreign Ministry official.

After the 1987 violence, Saudi Arabia imposed a quota of pilgrims from each country. Iran has boycotted the hajj for the past three years to protest its quota of 45,000. Iran also believes pilgrims should be permitted to hold political demonstrations during the hajj, a practice the Saudis oppose.

Iran's Tehran Times suggested that the Saudis had agreed to "rallies of antipathy toward unbelievers by pilgrims" and "seem to have offered" Iran a quota of 75,000 pilgrims. Iran, however, insisted on sending 150,000 pilgrims, the newspaper said.

Although Iran has criticized the presence of foreign -- principally U.S. -- military forces in the region, it is demonstrating understanding of Saudi Arabia's reasons for calling in those troops, a Saudi diplomat said.

"They are against the presence of the 'Devil,' the United States," he said, "but they are giving us the credit that we are asking to be protected. So this is balancing their stand in the area."