The domestic criticism started pouring in almost as soon as Israel’s cease-fire with Hamas was inked Wednesday night. Prime Minister Benjamin Netanyahu had waved a white flag and left the job unfinished, the opposition howled. A television snap poll found that a large majority of the public did not support the Egyptian-brokered truce.

Even so, many Israeli analysts said that for Netanyahu, a hawkish and shrewd politician who is seeking reelection in two months, the abrupt end to the eight-day hostilities in the Gaza Strip carried as many political benefits as risks. Although he has long vowed to safeguard Israel from terrorism, Gaza was never his battle. If the cease-fire holds — a major if — Netanyahu has several weeks to turn domestic and international focus back to his signature security issue: Iran.

The Israeli operation did not devastate Gaza’s Hamas rulers; in fact, it emboldened them regionally. And there is broad agreement in Israel that stunting Gaza militants’ ability to launch rockets at Israel should have been a quicker mission. But letting it drag on further, analysts and officials said, would only benefit Iran.

A lingering, bloodier war probably would have distracted the international attention Netanyahu has worked to center on Iran’s nuclear program and would have eroded European and American support. The cease-fire, Israel seemed to bet, might inject goodwill into its shaky alliance with Egypt and Netanyahu’s chilly relations with President Obama.

“This is what a responsible government does, and it is what we did here: We made use of our military might while applying political considerations,” Netanyahu said Wednesday after the cease-fire was announced.

Israel appeared motivated to avoid the international censure that clouded its last Gaza operation four years ago. It launched about 10 times as many airstrikes this time but caused about 10 times fewer Palestinian deaths.

In an interview Thursday, a senior Israeli official, who spoke on the condition of anonymity to discuss the politics of the military operation, argued that the Gaza offensive defied impressions of Netanyahu as a warmonger unconcerned about sparking regional conflict — the depiction offered by an array of ex-Israeli security officials opposed to an Israeli strike on Iran — and showcased “a responsible group here leading the country through a major crisis. . . . You didn’t see a group of extremists.”

Writing in the Jerusalem Post on Thursday, commentator Herb Keinon pronounced that as “the likely theme of [Netanyahu’s] campaign — military might with diplomatic prudence, restoring quiet, albeit temporarily, while retaining international legitimacy.” Although a cease-fire collapse could change his fortunes, Netanyahu is still viewed as the favorite in the coming elections.

During the Gaza operation, some Israeli observers surmised that it was launched partly to clear the decks for an attack on Iran — by destroying some of the weaponry Hamas might use to defend longtime sponsor Iran and by testing Israel’s U.S.-funded missile defense systems. The idea was echoed Wednesday before the cease-fire took hold by a senior Israeli military official, who told reporters that the offensive “was not only an event between us and Gaza. All the neighbors are looking . . . what is the Israeli performance here?”

Yet several analysts said the Gaza offensive accomplished little practical preparation for a potential war with Iran and was not intended to do so. Israeli officials said they destroyed a significant number, but by no means all, of the more than 10,000 rockets they thought were in Gaza, including the Fajr-5s that the commander of Iran’s Revolutionary Guard Corps boasted this week were supplied by his country. They also said many rocket launchers, weapons factories and arms-smuggling tunnels were razed.

Although the more than 80 percent success rate of Israel’s Iron Dome antimissile system soothed the public and might have served as a show of force to Tehran and its Hezbollah allies in Lebanon, the system’s performance says little about Israel’s ability to handle long-range missiles from Iran. A different, untested system would be deployed to deflect those.

“The general lesson is that missile defense is effective, it can work,” said Uzi Rubin, the former head of Israel’s missile defense program. “But Iron Dome has nothing to do with threats from Iran.”

But when it comes to Iran, retaining diplomatic legitimacy throughout the Gaza operation was most important to Netanyahu, analysts said.

At the United Nations in September, Netanyahu suggested that the window for a strike on Iran’s nuclear facilities was open until spring or summer, and Israel has recently given more credence to the idea that sanctions might pressure Iran to negotiate. The Israeli security establishment and public are strongly against an Israeli attack on Iran without U.S. backing, meaning that the idea is “more and more discredited,” said Meir Javedanfar, who teaches Iranian politics at the Interdisciplinary Center in Herzliya, Israel.

Even more important, he said, is that Hamas, an Islamist movement that Israel and many Western countries label a terrorist organization, has moved away from Iran over the latter’s support for Syrian President Bashar al-Assad. By backing a cease-fire brokered by Islamist Egyptian President Mohamed Morsi, Israel and the United States endorsed the Egypt-Israel alliance and Hamas’s pivot away from Iran’s Shiite bloc toward a widening Sunni orbit in the post-Arab Spring Middle East.

“It’s bad for Iran if Hamas is turning to Egypt and not to Iran,” said an Obama administration official, who spoke on the condition of anonymity to discuss the sensitive diplomatic negotiations.

As Israel emerges from a rally-around-the-flag week and resumes the campaign season, Netanyahu is likely to face criticism for the cease-fire and securing what are by no means long-term gains against Hamas. Shaul Mofaz, head of the Kadima opposition party, said Hamas “got stronger.” Another opposition candidate, Yair Lapid, accused the government of “weakness.”

Giora Eiland, a retired major general and former national security adviser, said that what looks like a victory for Hamas might not be bad for Israel and Netanyahu if the rockets in southern Israel stop. Even the vaguely worded cease-fire agreement of “opening the crossings and facilitating the movement of people” — an apparent reference to easing Egypt’s and Israel’s partial blockades on the strip — might lead to more Egyptian monitoring of weapons flows into Gaza and foreign investment in the coastal enclave. The latter would give Hamas reason to restrain smaller militant factions and avoid confrontations with Israel, Eiland said.

“As far as Israel is concerned, we like this Hamas interest,” Eiland said. “It is better that the perception of Gaza is not considered an area of no man’s land that is controlled by militias.”

Then again, many Palestinians say, loosening Gaza’s southern border with Egypt will only further divide Gazans from Palestinians in the West Bank, which lies on the other side of Israel and is ruled by an authority led by a Hamas rival, Fatah. Their unity is widely viewed as key to a viable peace agreement with Israel and a two-state solution, and the Israeli official interviewed Thursday acknowledged that the Gaza conflict had strengthened Hamas at the expense of the Fatah-led Palestinian Authority.

That might not trouble Netanyahu. Although he says he supports a two-state solution, he has shown scant enthusiasm for peace talks that would lead to one.

Ruth Eglash in Jerusalem, Ernesto Londoño in Tel Aviv and Karen DeYoung in Washington contributed to this report.