KHAN YOUNIS, Gaza Strip — Nearly a year after a devastating war, Israel and Gaza’s Hamas rulers appear to have formed an unspoken alliance in a common battle against the shared threat of jihadis aligned with the Islamic State group.

While Israel and Hamas remain arch-enemies, both have an interest in preserving an uneasy calm that has prevailed since the fighting ended in a cease-fire last August – a stalemate that is largely the result of a lack of options on either side.

More than 2,200 Palestinians were killed in last year’s fighting, according to Palestinian officials, and Hamas suffered heavy losses. It is isolated internationally, Gaza’s economy is in tatters and reconstruction efforts have moved slowly.

A renewal of hostilities would be devastating for Gaza’s 1.8 million people.

On the Israeli side, 73 people, including 67 soldiers, were killed in last year’s fighting, and the summer-long war disrupted the lives of millions of people as they coped with repeated rocket attacks and air-raid sirens. But Hamas, which seized power in Gaza eight years ago, has survived three wars, and the cost of toppling the group would be extremely high, so Israel appears content to contain Hamas and keep things quiet.

Hamas officials say that efforts are underway, through Qatari mediators, to work out a long-term cease-fire. The deal would call for Israel to ease a stifling blockade on Gaza in exchange for Hamas pledges to disarm, the officials said, speaking on condition of anonymity because they were discussing sensitive negotiations.

In the short run, the biggest threat to the quiet is a small but growing number of extremists in Gaza inspired by the Islamic State group, who have fired rockets across the heavily guarded frontier in order to undermine Hamas. The militants believe Hamas is soft on Israel and has failed to establish an Islamic state.

That has transformed Israel and Hamas – enemies for nearly three decades – into unspoken allies against a shared threat.

Nowhere is this more evident than in the southern town of Khan Younis, where Hamas militants have been supervising work crews that are opening a road along Gaza’s eastern fence with Israel. The patrols have helped preserve quiet in a volatile area used in the past by rocket-launching squads.

Hamas officials say that maintaining the cease-fire is a national interest.