Hamas and other militant groups said Tuesday they had accepted an Egyptian-brokered ceasefire to end two days of intense fighting with Israel that had pushed the sworn enemies to the brink of a new war.

The sudden announcement brought relief to a region that had been paralyzed by hundreds of Palestinian rocket attacks in southern Israel and scores of Israeli airstrikes on targets in the Gaza Strip. But it did not address the deeper issues that pushed Israel and Gaza's Hamas rulers toward their latest violence and left doubts about international efforts to forge a broader truce.

Those efforts had appeared to be making progress in recent days as Israel allowed Qatar to deliver financial aid to the cash-strapped Hamas government, and Prime Minister Benjamin Netanyahu declared that he wanted to avert an "unnecessary" war in Gaza. Hamas, in turn, had scaled back its mass protests that have led to weekly bloodshed along the Israeli border.

But hours after Netanyahu spoke Sunday, an Israeli commando unit on an undercover mission was caught behind enemy lines in Gaza by Hamas militants. Their discovery set off a battle that led to the deaths of seven militants and an Israeli officer, and triggered the heaviest barrage of rocket fire since a 2014 war.

The Israeli military said that Palestinian militants fired 460 rockets and mortars into Israel in a 24-hour period, while it carried out airstrikes on 160 targets in Gaza. Seven Palestinians, including five militants, were killed, and 26 people were wounded. In Israel, a 48-year-old Palestinian laborer was killed in a rocket strike on an apartment building where he was staying. Nearly 30 people were wounded, three critically.

With air raid sirens wailing throughout southern Israel and the explosions of airstrikes thundering in Gaza, the sides had appeared to be headed to what would have been their fourth war in a decade.

But late Tuesday, Hamas and other military groups issued a joint statement saying they had accepted an Egyptian-brokered ceasefire.

An injured Israeli woman arrives at a hospital in Ashkelon on Monday. The Magen David Adom medical service said a man was found dead in the Israeli coastal city as a result of rocket attacks from the Gaza Strip. (Gil Cohen-Magen/AFP/Getty Images)

'Mutal commitment' to ceasefire

Terms of the deal appeared to be modest. Daoud Shehab, a spokesman for the Islamic Jihad militant group, said each side would promise quiet in exchange for quiet.

"It's a mutual commitment to the ceasefire," he said. "From our side, we responded positively to the Egyptian endeavour on the condition that the occupation does the same."

The announcement set off celebrations in Gaza City as Hamas supporters declared victory.

At a demonstration staged in the rubble of Hamas's TV station, demolished by an Israeli airstrike, crowds chanted the name of Hamas's military wing. Shops reopened and cars jammed the streets. Israeli reconnaissance drones continued to buzz overhead.

Ismail Radwan, a Hamas official, expressed Hamas's commitment to the ceasefire but warned that "our hands are on the trigger" if Israel violates the agreement.

In Israel, officials had no official comment on the ceasefire claim, as dozens of protesters in the rocket-battered town of Sderot chanted "Disgrace!" at what they saw as the government's capitulation to militant violence. But after nightfall, both the rocket attacks and Israeli airstrikes had stopped.

A report in the Israeli newspaper Haaretz said both Israel and the Palestinian factions agreed to the ceasefire, announced shortly after Netanyahu's security cabinet ended a seven-hour discussion on the rising tensions.

Residents of southern Israel protest against their government's decision to hold fire in Gaza in response to a similar decision by Palestinian militants, in Sderot, Israel on Tuesday. (Amir Cohen/Reuters)

Israel to 'continue operations as needed'

The cabinet said it had ordered the military to "continue operations as needed." Israel's Channel 10 TV reported deep divisions among the participants, with several hard-line ministers reportedly opposed to another ceasefire with Hamas.

Hamas, an Islamic militant group that opposes Israel's existence, consolidated control of the Gaza Strip in 2007.

An Israeli soldier walks by a house in Ashkelon that was damaged by a missile fired from the Gaza Strip. (Tsafrir Abayov/Associated Press)

Israel and Egypt immediately imposed a blockade on Gaza to contain Hamas. Tuesday's ceasefire did not appear to address any of the underlying issues, including the blockade and Hamas's vast arsenal of rockets, and it was unclear whether UN and Egyptian efforts toward a broader deal might resume.

UN and Egyptian mediators had been making progress in recent weeks toward informal understandings between Israel and Hamas that would ease the blockade in exchange for ratcheting down the border protests.

Demonstrators each week approach the border fence, throwing firebombs, grenades and burning tires at Israeli troops. Israeli snipers have killed about 170 people, most of them unarmed. Israel says it is defending its border against attackers, but it has come under heavy international criticism for shooting unarmed people.

In recent days, Israel allowed fuel shipments to increase the power supply in Gaza, which suffers from frequent blackouts, and agreed to additional Qatari assistance to allow Hamas to pay the salaries of its thousands of unpaid workers.

An explosion is seen during an Israeli airstrike on Hamas's television station in Gaza City on Monday. (Ahmed Zakot/Reuters)

A diplomatic official said the ceasefire included an "understanding" to return to a 2014 ceasefire that promised some relief for Gaza in exchange for quiet.

The official said he expected a return to the situation before the latest burst of violence and for mediators to resume their efforts. He spoke on condition of anonymity because he was not authorized to discuss the matter with the media.

The UN Security Council scheduled closed consultations on the Hamas-Israel clashes later Tuesday at the request of Kuwait and Bolivia, UN diplomats said.

With files from CBC News