DUBAI—Saudi Arabia and other oil-rich Persian Gulf states have tried to avoid taking a position on America’s geopolitical rivalries in recent years, staying neutral in the Ukraine war and building ties with China. With Israel and Iran in open conflict, they might be forced to choose a side.

Saudi Arabia and the United Arab Emirates struggled to stay on the sidelines when it became clear last week that Iran would attack Israel in retaliation for a strike in Syria that killed senior Iranian military officers.

The Saudis and Emiratis shared intelligence that contributed to an overwhelmingly successful defensive response to a sprawling Iranian air attack, said Arab officials. However, they stopped short of giving Washington everything it wanted, denying the U.S. and Israel use of their airspace to intercept missiles and drones, the officials said.

The confrontation showed both countries how difficult it is going to be to keep striking a careful balance between their chief Middle East rival, Iran; their most important security partner, the U.S.; and Israel, a powerful military that the Saudis and Emiratis have grown closer to in recent years but that they both criticize harshly over its conduct in its war in Gaza .

If the Israel-Iran conflict escalates and draws in the U.S., the Gulf Arab states would likely have a stark choice: allow American forces to launch attacks from bases in their countries and risk Iranian retaliation, or try to appease Iran and stay on the sidelines as they have largely done since the Oct. 7 attacks plunged the Middle East into turmoil.

Since Saturday’s attack, the U.A.E. has called for restraint and the need to achieve stability through diplomatic channels. “The region should avoid conflict at all costs, as it cannot sustain additional tensions and confrontations,” a U.A.E. official said.

Adding to the complexity for Saudi Arabia is its push to strike a broad deal that would recognize Israel in exchange for firm security commitments from the U.S. and help with its nuclear program. The deal’s momentum was stopped with the Gaza war, but the Saudis have indicated they still want better U.S. defense guarantees, which they feel Washington has abandoned in the past decade.

“Absent a U.S. commitment to their security, they would do their utmost to limit their cooperation and hide it from Iran,” said Bilal Saab, a former Pentagon official who worked on security cooperation in the Middle East and is now a fellow at the London-based Chatham House think tank.

The Saudis and the Emiratis earlier this year declined to participate publicly in a U.S.-led maritime coalition to confront attacks on Red Sea shipping by Yemen’s Houthi rebels, who threatened to strike participating countries. Along with Kuwait, they have also restricted the Pentagon from launching airstrikes against the Houthis from bases in their territory, say U.S. defense and Arab officials.

Gulf countries are wary of being seen by their populations as supporting Israel and the U.S. following more than six months of war in Gaza, where nearly 34,000 Palestinians have been killed.

But if the U.S. gets more deeply involved in the coming weeks in a direct confrontation with Iran, Arab governments are likely to find their room to maneuver shrinking, say Arab officials.

“If Iran escalates directly against American assets…then it is a moment of reckoning,” said Gregory Gause, a Middle East expert at Texas A&M University’s Bush School of Government and Public Service. “Because then Washington says, ‘If you want a partnership, you have to help us when we’re the target in the same way that you expect us to help you when you’re the target.’”

So far, Iran has said it doesn’t intend to target the U.S., and Washington says it won’t participate in an Israeli reprisal.

Gause said that the Gulf states have traditionally fluctuated between fearing they would become collateral damage when Washington was aggressive with Iran, and fearing they would be abandoned when the U.S. became more conciliatory toward Tehran.

“This is just baked in the cake,” he said. “It’s not something that you can solve.”

In recent years, Saudi Arabia and the U.A.E. have pursued detente with Iran following a period of severed ties.

A China-brokered deal a year ago re-established Saudi-Iranian relations, and since the start of the conflict, the kingdom has been attempting to deter Iran and its proxies from turning the Gaza war into a wider conflict by offering cooperation and investments in the Iranian economy.

Following the strike this month on Iran’s embassy in Damascus that triggered Saturday’s Iranian response , Gulf states were worried that Iran might strike Israeli embassies in the region and that the U.S. might not muster a strong response, Saudi officials said.

Iranian officials briefed counterparts from Saudi Arabia and other Gulf countries ahead of Saturday’s large-scale strikes on Israel on the outlines and timing of their plan so that those countries could safeguard airspace, the Saudi officials said. The information was passed along to the U.S., giving Washington and Israel crucial warning and demonstrating for Saudi officials that Riyadh’s warming to Tehran was paying off.

An anti-Israel billboard with a picture of Iranian missiles is seen on a street in Tehran, Iran April 19, 2024. Majid Asgaripour/WANA (West Asia News Agency) via REUTERS

Saudi and Emirati officials have also met in recent weeks with officials from Lebanese militant group Hezbollah in an effort to de-escalate its conflict with Israel, according to Arab and Hezbollah officials.

A senior Saudi official said that Crown Prince Mohammed bin Salman doesn’t want the war to distract from his ambitious plans to transform the kingdom’s economy.

“This war and the current escalation puts his plans at greater risk,” the official said. “MBS knows the Gulf countries would be the first impacted if war is expanded.”

The response to Saturday’s attack, which Israel fended off with cooperation from the U.S., European and Arab militaries, demonstrated the potential value of a partnership with Washington.

“This reinforces that when you’re aligned with the United States, you can protect your sovereignty in cooperation with both the United States and your neighbors,” said Jon Alterman , a Mideast expert at the Center for Strategic and International Studies think tank.

But after failing for years to secure more formal security pacts with the U.S. following Iranian-linked attacks that they felt the U.S. didn’t adequately respond to, Gulf states are now hesitant to put themselves in Iran’s crosshairs for the sake of the U.S.

Abdulkhaleq Abdulla, an Emirati political scientist, expects the U.A.E. to maintain relations with Iran and Israel despite what it considers destabilizing actions by both countries.

“The most wise course at the moment is to stay away from it all, keep focusing on its own national interest, its own security and try to stay out of it,” he said. “We don’t want to get entangled in this one way or another. That’s priority No. 1 in the U.A.E. and for the rest of the Arab Gulf states.”

Bernard Hudson, a veteran of the Central Intelligence Agency and the agency’s former counterterrorism chief, said that after a monthslong stalemate between Washington and Yemen’s Houthis, Saturday’s attack demonstrated that Iran is nearing security parity with the U.S. in the Middle East and a U.S. response risks failing to substantively diminish Iran’s military capacity.

“This isn’t going to be lost on the U.S.’s regional allies who increasingly are going to have to make their own security arrangements as the U.S. protective umbrella continues to leak,” he said.

Write to Summer Said at summer.said@wsj.com and Stephen Kalin at stephen.kalin@wsj.com