Prime Minister Benjamin Netanyahu of Israel is fighting two parallel battles, one in Gaza and another at home — and neither is going according to plan.

In Gaza, Mr. Netanyahu is leading a military campaign to defeat Hamas and free the remaining Israeli hostages captured during the Oct. 7 attack on Israel. At home, he is fighting to secure both his short-term political survival and his long-term legacy.

On both fronts, he is struggling.

In Gaza, more than 100 hostages remain captive despite months of war and protracted negotiations for their release. Hamas is battered but undefeated, and generals have privately said that the war, despite devastating Gaza and killing more than 26,000 people, according to officials there, is approaching a deadlock. In Israel, polls show the prime minister would easily lose an election if one were held tomorrow. And after Mr. Netanyahu presided over the defense failures on Oct. 7, the deadliest day in Israel’s history, his legacy has been ruined.

His efforts to resolve these crises are at odds with each other, analysts said.

To burnish his legacy, he is pushing for a landmark peace deal with Saudi Arabia, a long-term strategic goal for Israel. Saudi Arabia, however, will not normalize ties without an Israeli commitment to a two-state solution. And without greater cooperation from Saudi Arabia and its Arab allies, it will become harder for Israel to wind down its war in Gaza and plan for the territory’s future.

But to retain power and preserve his right-wing coalition, he must reject the premise of a Palestinian state.