A Palestinian family flashes victory signs as they celebrate the cease-fire between Palestinians and Israelis at the main road in Gaza, in the northern Gaza Strip, on Tuesday.

GAZA CITY, Gaza Strip — Israel and Gaza’s ruling Hamas agreed Tuesday to an open-ended cease-fire after seven weeks of fighting — an uneasy deal that halts the deadliest war the sides have fought in years, with more than 2,200 killed, but puts off the most difficult issues.

In the end, both sides settled for an ambiguous interim agreement in exchange for a period of calm. Hamas, though badly battered, remains in control of Gaza with part of its military arsenal intact. Israel and Egypt will continue to control access to blockaded Gaza, despite Hamas’ long-running demand that the border closures imposed in 2007 be lifted.

Hamas declared victory, even though it had little to show for a war that killed 2,143 Palestinians, wounded more than 11,000 and left some 100,000 homeless. On the Israeli side, 64 soldiers and six civilians were killed, including two killed by Palestinian mortar fire shortly before the cease-fire was announced.

Large crowds gathered in Gaza City after the truce took effect at dusk, some waving the green flags of Hamas, while celebratory gunfire and fireworks erupted across the territory.

Mahmoud Zahar, a senior Hamas leader, promised to rebuild homes destroyed in the war and said Hamas would rearm. “We will build and upgrade our arsenal to be ready for the coming battle, the battle of full liberation,” he declared, surrounded by Hamas gunmen.

The Israeli response was more subdued.

“This time we hope the cease-fire will stick,” said Israeli government spokesman Mark Regev. He portrayed the deal as one Hamas had rejected in previous rounds of negotiations.

Israeli Prime Minister Benjamin Netanyahu faced some criticism from hard-line critics and residents of Israeli communities near Gaza who said the deal failed to defuse the threat from Gaza militants. Since July 8, Hamas and its allies have fired some 4,000 rockets and mortars at Israel, and tens of thousands of Israelis evacuated areas near Gaza in recent weeks.

Under the Egyptian-brokered deal, Israel is to ease imports to Gaza, including aid and material for reconstruction. It also agreed to a largely symbolic gesture, expanding a fishing zone for Gaza fishermen from three to six nautical miles into the Mediterranean.

In a month, talks are to begin on more complex issues, including Hamas’ demand to start building a seaport and airport in Gaza. Israel has said it would only agree if Hamas disarms, a demand the militant group has rejected.

In Washington, State Department spokeswoman Jen Psaki said Tuesday that the agreement offers “an opportunity, not a certainty.”

“Today’s agreement comes after many hours and days of negotiations and discussions. But certainly there’s a long road ahead. ... We’re going into this eyes wide open,” she said. Early on in the war, U.N. chief Ban Ki-moon and U.S. Secretary of State John Kerry had tried in vain to broker a truce.

The cease-fire went into effect at 7 p.m. (1600 GMT) Tuesday, and violence persisted until the last minute.

About an hour before the cease-fire, 12 mortar shells hit an Israeli communal farm near Gaza, killing two Israelis and wounding seven other people, two of them critically, the Israeli military said. Between 5 p.m. and 7 p.m., Gaza militants fired 83 rockets, of which 13 were intercepted.

In Gaza, an Israeli airstrike minutes before the start of the cease-fire toppled a five-story building in the town of Beit Lahiya, witnesses said. Twelve Palestinians, including two children, were killed in several Israeli airstrikes before the truce took hold, Gaza police said.