A Hamas official said Sunday that Gaza militants have agreed to a ceasefire with Israel to stop three days of violence after a deadly attack on Israelis near the Egypt-Israel border set off a round of Israeli airstrikes and rocket barrages from Gaza.

The sudden flare-up also threatened Israel-Egypt relations after Egypt said five of its policemen were killed by Israeli fire as Israel's troops and aircraft pursued the militants responsible for killing eight people Thursday. Egypt complained strongly as thousands demonstrated in Cairo, and Israel apologized.

The senior Hamas official said Sunday afternoon that militant groups in Gaza agreed that the truce would go into effect Sunday evening. Hamas security personnel would enforce the agreement brokered by Egypt, the official said. He said Egypt told the groups that Israel would agree to halt its airstrikes only if the Palestinians stopped the rocket fire first.

A spokesman for Israel's government would not comment, and it was not clear if the ceasefire indeed had the backing of all of Gaza's armed factions.

Palestinian rocket fire and Israeli airstrikes continued hours after the ceasefire was to take effect at 9 p.m. local time.

Earlier Sunday, a salvo of rockets from Gaza struck an empty school and sent thousands of Israelis into bomb shelters. Israel responded with airstrikes and diplomats scrambled to limit the violence.

The diplomatic efforts were also aimed at limiting the damage from the deaths of the Egyptian policemen. On Sunday morning, an Israeli envoy arrived at Cairo's international airport and was whisked off in a convoy of four waiting cars, airport officials said. Israel's government would not comment on the envoy's identity or the details of his mission. A second unidentified envoy arrived later Sunday, the Egyptian officials said. France and Germany were also working with the Israelis and Egyptians to end the diplomatic spat, the officials said, speaking on condition of anonymity in order to discuss ongoing diplomatic efforts.

Alongside the diplomacy, Israel threatened to intensify its attacks if the rocket barrages continued.

Speaking to Israel Radio, military spokesman Brig.-Gen. Yoav Mordechai said Israel "will not hesitate" to widen its military operation if necessary. Diplomats scrambled to try to prevent the violence — the deadliest since Israel went to war against Gaza militants 2½ years ago — from spiralling out of control.

'An independent Palestinian state is the remedy for violence'

Large-scale Israeli military operations in Gaza would create new friction with the Muslim world at a time when Palestinian President Mahmoud Abbas is preparing to ask the United Nations to recognize an independent Palestinian state. Pictures of a major Israeli offensive in Gaza could hurt the Jewish state's efforts to minimize world support for the Palestinian statehood bid.

A spokesman said Abbas's Palestinian Authority planned to use the renewed violence to bolster its case for statehood at the UN next month.

"An independent Palestinian state is the remedy for violence," Husam Zomlot said. "It would control its borders and prevent such deterioration from happening."

Abbas, who wields limited power in the West Bank under Israel's overall security control, asserts no such control now.

Hamas routed his loyalists from Gaza in a violent 2007 takeover and a reconciliation pact the two sides signed in May has stalled.

Hamas, backed by Iran, opposes both peacemaking with Israel and Abbas's statehood bid.

Under Hamas rule, Gaza's militants have increased the quality and range of their rocket arsenals and now target the largest city in Israel's south — Beersheba, 40 kilometres away from Gaza. Most of the rockets launched since Thursday have been military-grade Katyushas smuggled in through tunnels from Egypt.

Israel pulled out of Gaza in 2005.

Since Thursday's ambush, militants have fired about 100 rockets and mortars into Israel. On Saturday, rockets killed an Israeli man in Beersheba and seriously wounded two others.