Israel was mere moments away from an airstrike on April 1 that killed several senior Iranian commanders at Iran’s embassy complex in Syria when it told the United States what was about to happen.

Israel’s closest ally had just been caught off guard.

Aides quickly alerted Jake Sullivan, President Biden’s national security adviser; Jon Finer, the deputy national security adviser; Brett McGurk, Mr. Biden’s Middle East coordinator; and others, who saw that the strike could have serious consequences, a U.S. official said. Publicly, U.S. officials voiced support for Israel, but privately, they expressed anger that it would take such aggressive action against Iran without consulting Washington.

The Israelis had badly miscalculated, thinking that Iran would not react strongly, according to multiple American officials who were involved in high-level discussions after the attack, a view shared by a senior Israeli official. On Saturday, Iran launched a retaliatory barrage of more than 300 drones and missiles at Israel, an unexpectedly large-scale response, if one that did minimal damage.

The events made clear that the unwritten rules of engagement in the long-simmering conflict between Israel and Iran have changed drastically in recent months, making it harder than ever for each side to gauge the other’s intentions and reactions.

Since the Oct. 7 attack on Israel by Hamas, an Iranian ally, and Israel’s subsequent bombardment of the Gaza Strip, there has been escalation after escalation and miscalculation after miscalculation, raising fears of a retribution cycle that could potentially become an all-out war.

Even after it became clear that Iran would retaliate, U.S. and Israeli officials initially thought the scale of the response would be fairly limited, before scrambling to revise their assessment again and again. Now the focus is on what Israel will do next — and how Iran might respond.

“We are in a situation where basically everybody can claim victory,” said Ali Vaez, the Iran director of the International Crisis Group. “Iran can say that it took revenge, Israel can say it defeated the Iranian attack and the United States can say it successfully deterred Iran and defended Israel.”

But Mr. Vaez said: “If we get into another round of tit for tat, it can easily spiral out of control, not just for Iran and Israel, but for the rest of the region and the entire world.”

This account of these tense weeks is gleaned from interviews with U.S. officials, as well as officials from Israel, Iran and other Middle Eastern states. All of them spoke on the condition of anonymity to discuss sensitive matters they were not authorized to reveal publicly.

Planning for the Israeli strike in Syria started two months earlier, two Israeli officials said. The target was Mohammad Reza Zahedi, the commander for Syria and Lebanon of Iran’s elite Quds Force, a branch of the Islamic Revolutionary Guards Corps.

About a week beforehand, on March 22, the Israeli war cabinet approved the operation, according to internal Israeli defense records that summarized preparations for the strike and were viewed by The New York Times. The Israeli military did not comment on the internal assessment.

Those records also outlined the range of responses from Iran that the Israeli government expected, among them small-scale attacks by proxies and a small-scale attack from Iran. None of the assessments predicted the ferocity of the Iranian response that actually occurred.

From the day of the strike, Iran vowed retaliation, both publicly and through diplomatic channels. But it also sent messages privately that it did not want outright war with Israel — and even less so with the United States — and it waited 12 days to attack.

American officials found themselves in an odd and uncomfortable position: They had been kept in the dark about an important action by a close ally, Israel, even as Iran, a longtime adversary, telegraphed its intentions well in advance. The United States and its allies have spent weeks engaged in intensive diplomacy, trying to tamp down first the expected Iranian counterattack, and now the temptation for Israel to reply in kind.

When it came this past Saturday night, Iran’s show of force was significant, but Israel, the United States and other allies intercepted nearly all of the missiles and drones. The few that reached their targets had little effect. Iranian officials say the attack was designed to inflict limited damage.

U.S. officials have been telling Israeli leaders to see their successful defense as a victory, suggesting that little or no further reply is needed. But despite international calls for de-escalation, Israeli officials argue that Iran’s attack requires yet another response, which Iran says it would answer with still more force, making the situation more volatile.

“The question now is how does Israel respond in a way to prevent Iran from rewriting the rules of the game without provoking a new cycle of state-on-state violence,” said Dana Stroul, a former top Middle East policy official at the Pentagon who is now at the Washington Institute for Near East Policy.

In fact, Israeli leaders came close to ordering widespread strikes in Iran on the night Iran attacked, according to Israeli officials.

Israeli officials say the Oct. 7 attack by Hamas, which caught them by surprise, changed the ground rules of regional conflict. To its enemies, it was Israel’s bombing and invasion of Gaza that did that, and it led to increased rocket fire by Hezbollah, Iran’s proxy in Lebanon. That in turn drew heavy fire from Israel.

The Israeli airstrike in Damascus killed seven Iranian officers, three of them generals, including Mr. Zahedi. In the past, Israel had repeatedly killed Iranian fighters, commanders and nuclear scientists, but no single strike had wiped out so much of Iran’s military leadership.

By March, the relationship between the Biden administration and Israel had grown increasingly fraught, as Washington criticized the Israeli assault in Gaza as needlessly deadly and destructive — “over the top,” as President Biden put it.

Then came the Israeli strike in Damascus. Not only did the Israelis wait until the last minute to give word of it to the United States, but when they did so, it was a relatively low-level notification, U.S. officials said. Nor was there any indication how sensitive the target would be.

The Israelis later acknowledged that they had badly misjudged the consequences of the strike, U.S. officials and an Israeli official said.

Defense Secretary Lloyd J. Austin III complained directly to Israel’s defense minister, Yoav Gallant, in a call on April 3, U.S. officials said, confirming an earlier report by The Washington Post. Mr. Austin said that the attack put U.S. forces in the region at risk, and that the lack of warning had left no time to ratchet up their defenses. Mr. Gallant had no immediate comment.

The vulnerability of thousands of U.S. troops deployed in the Middle East became all too clear earlier in the Israel-Hamas war, when Iranian-backed militias fired on them repeatedly, killing three and injuring more than 100. Those attacks stopped in early February only after retaliation by the United States and ominous warnings to Iran.

The night of the Damascus strike, Iran’s Ministry of Foreign Affairs summoned the Swiss ambassador in Tehran to convey Iran’s outrage to Washington, along with the message that it viewed the United States, Israel’s primary backer, as accountable for the attack.

Using Oman, Turkey and Switzerland as intermediaries — Iran and the United States do not have formal diplomatic relations — the United States made clear to Iran that it had not been involved and that it did not want war.

The Iranian government went on an unusually open and broad diplomatic campaign, spreading the word that it saw the attack as a violation of its sovereignty that required retaliation.

The government publicized that it was exchanging messages with the United States and that Foreign Minister Hossein Amir Abdollahian was speaking with representatives of countries in the region, high-level European officials and leaders of the United Nations.

On April 7, Mr. Abdollahian met in Muscat, Oman, with his Omani counterpart, Badr Albusaidi. Oman is one of the main intermediaries between Tehran and the West. The Iranian message at that meeting, according to a diplomat briefed on it, was that Iran had to strike back but that it would keep its attack contained, and that it was not seeking a regional war.

Before and after that meeting there was a whirlwind of phone calls between Gen. Charles Q. Brown Jr., chairman of the Joint Chiefs of Staff; Secretary of State Antony J. Blinken; Mr. Biden; Mr. Austin; Mr. Sullivan; their counterparts in Israel, China, India and Iraq; NATO allies; and others, officials said.

The Biden administration did not think it could dissuade Iran from attacking at all, a U.S. official said, but hoped to limit the scale.

Mr. Blinken talked to senior Israeli cabinet members, assuring them that the United States would help defend against an Iranian attack, and urging them not to mount a rash counterstrike without weighing all considerations.

American and Israeli intelligence agencies worked closely together, with help from Jordan and other Middle Eastern countries, to learn what they could about Iran’s intentions.

Intermediaries and allies told the United States and Israel that Iran planned to hit military sites and not civilian targets, U.S. and Israeli officials said.

Iran’s message was that it would temper its attack so as not to elicit an Israeli counterstrike, Israeli and Iranian officials said. But in reality, the Israelis said, Iran was expanding its attack plans, and wanted at least some of its weapons to penetrate Israel’s defenses.

Initially, Israel’s military and intelligence services expected Iran to launch no more than 10 surface-to-surface missiles at Israel, an attack they code-named “Late Foliage.” By the middle of last week, they realized Iran had something much bigger in mind, and the Israelis increased their estimate to 60 to 70 surface-to-surface missiles. Even that turned out to be too low.

On Wednesday, Mr. Biden publicly reinforced what he and his aides had repeatedly said: Despite friction with Prime Minister Benjamin Netanyahu, the American commitment to defending Israel from attacks was “ironclad.”

Still, the Biden administration also redoubled its diplomatic efforts to head off a confrontation, and Iranian officials said their government fielded calls last week urging restraint from countries across Asia, Europe and Africa — an effort they described as frantic.

Turkey, relaying an Iranian message, told the United States that Iran’s attack would be proportionate to the Damascus strike, according to a Turkish diplomatic source. Mr. Abdollahian, Iran’s foreign minister, told state television the day after the Iranian barrage that Iran had given its neighbors 72 hours’ notice of the attack, though the specifics of that warning are unclear.

Israeli officials say that, thanks in part to international cooperation, they had a good idea in advance of Iran’s targets and weapons. The Israel Defense Forces evacuated families from some air bases and moved aircraft out of harm’s way.

The U.S. military coordinated aerial defense efforts with Israeli, British and French forces as well as — crucially — those of Jordan, which lies between Iran and Israel. The United States and Israel had been working quietly for years with friendly Arab countries to develop a regional air defense system with shared detection and alerts. The effort picked up steam after several drone attacks against Saudi Arabian oil facilities in 2019.

News of the first wave of the Iranian attack on Saturday, consisting of 185 relatively slow drones, spread worldwide hours before any of them reached Israel. The three dozen cruise missiles Iran launched later were much faster, but the biggest challenge was Iran’s ballistic missiles, which traveled several times as fast as the speed of sound. Iran fired 110 of them, posing the first major test of Israel’s anti-ballistic missile defense system.

American, British, French, Israeli and Jordanian warplanes and air defense systems shot down most of the drones and missiles before they reached Israel. Only 75 entered Israeli airspace, where most of those were shot down, too, Israeli officials said. The attack did only minor damage to one air base, and only one serious injury was reported.

Throughout the strike, Iran’s Foreign Ministry and the Revolutionary Guards kept open a hotline to Oman’s government, to pass messages back and forth with the United States, Iranian officials said.

At 3 a.m., the Swiss ambassador in Tehran was summoned again — not to the Foreign Ministry, the usual practice, but to a Revolutionary Guards base, according to an Iranian and a U.S. official. She was asked to convey a message that the United States should stay out of the fight, and that if Israel retaliated, Iran would strike again, harder and without warning.

Iran cast its barrage against Israel as a measured, justified act that should not lead to escalation.

“We carried out a limited operation, at the same level and proportion to the evil actions of the Zionist regime,” Maj. Gen. Hossein Salami, commander in chief of the Revolutionary Guards, said on state television. “These operations could have been a lot larger.”

Mr. Biden told Mr. Netanyahu in a call that Israel’s successful defense had demonstrated its technical superiority, according to John F. Kirby, a spokesman for the National Security Council.

“The president urged the prime minister to think about what that success says all by itself to the rest of the region,” Mr. Kirby said on Monday.

But in interviews, Israeli officials described the attack in far more dire terms, in part because of its sheer scale. They emphasized that this was a sovereign nation, from its own soil, attacking Israel directly, and not through proxies abroad.

Israel’s war cabinet had ordered the military to draw up plans for a wide-ranging set of strikes against targets in Iran in the event of a large-scale Iranian attack. After news came of the Iranian launches on Saturday, some leaders argued behind closed doors that Israel should retaliate immediately.

Waiting, they said, would allow international pressure for Israeli restraint to build, and could let Iran think that it had set new ground rules for the conflict, which Israel considered unacceptable. Among the leaders making that argument, according to three Israeli officials, were Benny Gantz and Gadi Eisenkot, former military chiefs of staff who were in the Parliamentary opposition to Mr. Netanyahu’s right-wing government and are usually considered less hawkish, but who joined the war cabinet last fall.

The Israeli Air Force was ready to carry out the order, but it never came. On Saturday night, after Mr. Netanyahu spoke with Mr. Biden, and because the damage was limited, the war cabinet postponed a decision, and more postponements followed.

The world is still waiting to see what Israel will do.

Reporting was contributed by Sheera Frenkel, Isabel Kershner, Michael Crowley, Vivian Nereim and Safak Timur.

world