For more than four decades, Iran’s rulers have pledged to destroy Israel. The supreme leader, Ayatollah Ali Khamenei, rarely appears in public without wearing a black-and-white checkered Palestinian kaffiyeh.

Iranian military commanders gloat over training and arming groups across the region that are enemies of Israel, including Hezbollah and Hamas. And when Hamas conducted the Oct. 7 terror attack on Israel that killed 1,400 people, Iranian officials praised it as a momentous achievement, shattering the Jewish state’s sense of security.

Now Iran faces a dilemma, weighing how it and its proxy militias — known as the axis of resistance — should respond to Israel’s invasion of Gaza and the killing of thousands of Palestinians, and whether to bolster its revolutionary credentials at the risk of igniting a broader regional war.

“There is no need for Iran to directly get involved in the war and attack Israel itself because it has the resistance axis militia who follow Iran’s policies and strategies and act on its behalf,” said Nasser Imani, an analyst close to the government, in a telephone interview from Tehran. “Right now Iran is in control mode — it is telling all of them, including Hezbollah, to keep things boiling but have restraint.”

For the time being, Iranian officials are publicly signaling they do not want a full-scale war.

“I want to reiterate that we are not pursuing the spreading of this war,” Iran’s foreign minister, Hossein Amir Abdollahian, said in a recent interview at Iran’s mission to the United Nations. He was in New York to attend U.N. meetings related to the war. But, he added, “The region is at a boiling point and any moment it may explode and this may be unavoidable. If this happens, all sides will lose control.”

He warned that regional militias in Lebanon, Yemen, Iraq and Syria could open multiple fronts against Israel, with a high potential “that the result will be that things will not go the way that Israel’s regime wants.” He did not elaborate on what would prompt the groups, which he said act independently.

Still, Iran does not want regional war, which carries risks for the nation and its religious rulers, according to three Iranians connected to the government who are familiar with internal deliberations and insisted on anonymity to discuss sensitive security matters. The military capabilities of its allies could be significantly diminished by a protracted battle with Israel, and even more so if the U.S. military enters the fray.

The Islamic Republic views the militias as its extended arms of influence, able to strike while affording Tehran a measure of deniability. They give Iran leverage in international negotiations and a means of tilting the balance of power in the Middle East away from archenemies like Israel and the United States, and rivals like Saudi Arabia.

But if Iran does nothing, its fiery leaders risk losing credibility among constituents and allies. Some Iranian hard-line conservatives have questioned why Iran’s actions are not matching its rhetoric to “free Al Quds,” or Jerusalem, from Israel’s rule. Many supporters of Iran’s government have even symbolically signed up as volunteers to be deployed to Gaza and fight Israel.

“In the first scenario Iran risks losing an arm; in the second scenario, Iran risks losing face,” said Ali Vaez, the Iran director of the International Crisis Group, a conflict prevention research and advocacy group. “Iran might try to square this circle by allowing its allies to escalate their attacks against Israel and the U.S. in a calibrated manner.”

Hezbollah in Lebanon and the Houthi militia in Yemen have launched recent attacks on Israel, but they have been limited in scope. The goal, for now, is not all-out war but to keep Israel’s military under pressure, possibly limiting its ability to wage war against Hamas, the people familiar with Iran’s strategy said.

Hezbollah, one of Iran’s closest and most powerful allies, and Israel have traded artillery and small-arms fire many times since Oct. 7, but they have kept their attacks to the border areas. Hassan Nasrallah, Hezbollah’s leader, is expected to deliver his first public remarks since the war began on Friday, which observers anticipate will set the tone for what the group does next.

“We have said from the beginning that we are present in this war,” Hashem Safieddine, head of Hezbollah’s executive council, said to Iranian media on Tuesday. Hezbollah will not discuss its plans, he added, because “we will act when necessary, we don’t talk.”

The Houthis have signaled their involvement, too, launching missiles and drones — including a barrage on Tuesday — that American and Israeli forces have shot down.

“There is total coordination at every level among all the heads of the resistance axis,” the Houthi spokesman Mohammed al-Bukhaiti told Iranian media on Tuesday.

Mehdi Mohammadi, an adviser to Gen. Mohammad Ghalibaf, the speaker of Iran’s Parliament and a commander of the Revolutionary Guards Corps, said in a Telegram post that regional militants were deliberately being calculated. “In practice, other fronts have already been opened but the scope of the attacks is being controlled,” Mr. Mohammadi said.

Iranian-backed militant groups in Iraq and Syria have ratcheted up attacks on U.S. military bases in both countries after a period of quiet. Tehran wants to apply pressure on the Biden administration to rein in Israel, or at least appear to make the United States pay a price for its staunch support of Israel.

In retaliation, American forces bombed facilities in Syria last Thursday that the Pentagon said were outposts of Iran’s Revolutionary Guards Corps. Mr. Amir Abdollahian called the U.S. strikes “for show.”

Mr. Imani, the analyst in Tehran, said there was no dispute that Iran had helped fund, train and arm the militants, and had supplied technological know-how to build their own arsenal of drones and rockets — especially in Gaza and Yemen, where blockades make it all but impossible to deliver heavy weaponry.

The Iranians familiar with government deliberations say Iran and Hezbollah are watching whether Hamas faces a serious existential threat from Israel, which would prompt them to accelerate attacks on Israel. Senior commanders of Iran’s Quds Forces and Hezbollah think that if Israel succeeds in wiping out Hamas, it will then come for them, the Iranians said. The Quds Forces commander Gen. Esmail Ghaani has been in Beirut for most of the past three weeks, the Iranians said.

The deputy commander of Iran’s Revolutionary Guards Corps, Brig. Gen. Ali Fadavi, said in a speech at a ceremony supporting Gaza on Oct. 22 that “if necessary, Iran will fire missiles toward Haifa,” according to Iranian media. He said Iran had helped transform Palestinian groups’ military capabilities from “rocks and arrows” to “drones and missiles.”

The risk of the war spreading has alarmed the United States and Israel. The Biden administration publicly warned Iran and its proxies not to widen the conflict, signaling that it does not seek war with Iran and urging Tehran to restrain its allies.

Mr. Amir Abdollahian confirmed that Iran and the United States were exchanging messages. “We told the Americans clearly that when you stand full force with the Zionist regime during a war, America is not in a position to tell others to have restraint,” he said.

But for all sides, the risk remains high of miscalculations that could make the conflict spiral out of control.

“Besides what Tehran can control, there is also the perilous possibility that some of its regional partners with looser ties, or a track record of ignoring Iranian advice, engage in uncoordinated action that puts Tehran in face of a fait accompli,” said Mr. Vaez. “For nearly four decades, Iran’s forward defense policy has protected its own soil against foreign attacks. The conflict in Gaza is testing the limits of that policy in an unprecedented fashion.”