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

Even so, many Israeli analysts said that for Netanyahu, a hawkish and shrewd politician who is seeking re-election 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 Netanyahu’s battle. If the cease-fire holds — a major if — Netanyahu now has several weeks to turn domestic and international focus back to his signature security issue: Iran.

The Israeli operation did not destroy Gaza’s Hamas rulers, and even emboldened them regionally, and there is broad agreement in Israel that the offensive lasted too long to accomplish a fairly narrow mission of stunting Gaza militants’ ability to launch rockets at Israel.

But letting it drag out further, analysts and officials said, would only benefit Iran.

A lingering, bloodier war probably would have distracted the international attention Netanyahu has worked almost obsessively to center on Iran’s nuclear program, and eroded European and American support.

The cease-fire, Israel seemed to bet, might inject goodwill into Israel’s 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.

Throughout the operation, 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 condition of anonymity to discuss the politics of the military offensive, argued that the Gaza offensive defied impressions of Netanyahu as a warmonger unconcerned about sparking regional conflict — the depiction of an array of former Israeli security officials opposed to an Israeli strike on Iran — and instead 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 Thursday, commentator Herb Keinon pronounced that as “the likely theme of (Netanyahu’s) campaign (was) 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 upcoming elections.

During the Gaza operation, some Israeli observers surmised that it was launched partially to clear the decks for an attack on Iran, by destroying some weaponry Hamas might use to defend longtime sponsor Iran and by testing Israel’s U.S.-funded missile defense systems.

The idea was echoed by a senior Israeli military official Wednesday, before the cease-fire took hold, who said 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 prep work 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 believed were in Gaza, including the Fajr-5s that the commander of Iran’s Revolutionary Corps boasted this week were supplied by Iran.

They also said many rocket launchers, weapons factories and arms-smuggling tunnels were razed.

And while the 80-percent-plus success rate of Israel’s Iron Dome anti-missile system soothed the Israeli public and might have served as a show of force to Tehran and its heavily armed Hezbollah allies in Lebanon, the system’s performance says little about Israel’s ability to handle volleys of long-range missiles from Iran. A different, untested anti-missile system would be deployed to deflect those.