Israel and the Hamas militant group agreed to a cease-fire Wednesday to end eight days of the fiercest fighting in nearly four years, promising to halt attacks on each other and ease an Israeli blockade constricting the Gaza Strip.

The deal was brokered by the new Islamist government of Egypt, solidifying its role as a leader in the quickly shifting Middle East after two days of intense shuttle diplomacy that saw U.S. Secretary of State Hillary Rodham Clinton race to the region. Under the agreement, Egypt will play a key role in maintaining the peace.

Standing next to Clinton, Egypt's foreign minister, Mohammed Kamel Amr, announced the breakthrough and said the deal was set to take effect at 9 p.m. local time. (2 p.m. EDT), capping days of intense efforts that drew the world's top diplomats into the fray.

The agreement will "improve conditions for the people of Gaza and provide security for the people of Israel," Clinton said at the news conference in Cairo.

In Israel, Prime Minister Benjamin Netanyahu's office said he agreed to the cease-fire after consulting with President Barack Obama.

Israel launched the fierce Israeli offensive in Gaza on Nov. 14 to stop months of intensifying rocket attacks, subjecting t. Even after the deal was announced, air raid sirens continued to wail in southern Israel.

In the last-minute burst of fire, Palestinian militants fired several bursts of rockets, Israeli authorities said. One rocket hit a house in the southern city of Beersheba, police said. No injuries were reported.

Israel launched well over 1,500 airstrikes and other attacks on targets in Gaza, while more than 1,000 rockets pounded Israel. In all, more than 140 Palestinians, including dozens of civilians, were killed, while five Israelis died in the fighting.

According to a copy of the agreement obtained by The Associated Press, Israel and all Palestinian militant groups agreed to halt "all hostilities." For the Palestinians, that means an end to Israeli airstrikes and assassinations of wanted militants. For Israel, it brings a halt to rocket fire and attempts at cross-border incursions from Gaza.

After a 24-hour cooling off period, it calls for "opening the crossings and facilitating the movement of people and transfer of goods, and refraining from restricting residents free movement."

Hamas officials said details on the new border arrangements would have to be negotiated.

Israel imposed its blockade of Gaza after Hamas, a militant group sworn to Israel's destruction, seized control of the territory five years ago. It has gradually eased the closure, but continues to restrict the movement of certain goods through Israeli-controlled crossings. Among the restrictions: a near-complete ban on exports, limited movement of people leaving the territory, and limits on construction materials that Israel says could be used for military use.

The deal was vague on what limits Israel would lift, and whether Gaza's southern passenger terminal on the Egyptian border would be expanded to allow cargo to pass through as well. The deal was also unclear about a key Israeli demand for an end to arms smuggling into Gaza in tunnels underneath the border with Egypt.

Under the agreement, Egypt will play a key role. It said "Egypt shall receive assurances from each party" that they are committed to the deal.

"Each party shall commit itself not to perform any acts that would break this understanding," it adds. "In case of any observations, Egypt — as the sponsor of this understanding — shall be informed to follow up."

The deal marked a key victory for Egypt's new Islamist government, which is caught in a balancing act between its allegiance to Hamas and its need to maintain good relations with Israel and the U.S. Hamas is an offshoot of Egypt's ruling Muslim Brotherhood.

The agreement came after Clinton shuttled across the region to help broker an end to the violence. She ended her meetings in Cairo, where Egyptian President Mohammed Morsi mediated between Israel and Hamas. U.N. chief Ban Ki-moon also flew across the region as part of the diplomatic cease-fire push.

Hours before the the deal was announced, a bomb exploded on a bus in Tel Aviv near Israel's military headquarters that wounded 27 people and led to fears of a breakdown in the shuttle diplomacy Clinton and U.N. chief Ban Ki-moon were conducting in the region.

The blast, which left the bus charred and its windows blown out, was the first bombing in Tel Aviv since 2006. It appeared aimed at sparking Israeli fears of a return to the violence of the Palestinian uprising last decade, which killed more than 1,000 Israelis in bombings and shooting attacks and left more than 5,000 Palestinians dead as well.

The blast was from a device placed inside the bus by a man who then got off, said Yitzhak Aharonovich, Israel's minister of internal security,

While Hamas did not take responsibility for the attack, it praised the bombing.

"We consider it a natural response to the occupation crimes and the ongoing massacres against civilians in the Gaza Strip," Hamas spokesman Fawzi Barhoum told The Associated Press.

Bassem Ezbidi, a West Bank political analyst, said it was unlikely Hamas itself was behind the attack, since it would not want to risk losing any of the international support it gained in recent days.

"If Hamas wants to target civilians it would do so by firing rockets, but not by buses because such attacks left a negative record in the minds of people. Hamas doesn't need this now," he said.

The bombing came as 10,000 Palestinians sought shelter in 12 U.N.-run schools, after Israel dropped leaflets urging residents to vacate their homes in some areas of Gaza to avoid being hit by airstrikes, said Adnan Abu Hassna, the U.N. Relief and Works Agency spokesman.

The influx of displaced people came a day after the head of UNRWA, Filippo Grandi, warned that the agency urgently needed $12 million to continue distributing food to the neediest Gazans. The agency runs schools, shelters and food programs for hundreds of thousands of Palestinian refugees and their descendants in Gaza.

Huge clouds of black smoke rose above the Gaza City skyline Wednesday as airstrikes pounded a sports stadium, used as a launch site for rocket attacks on Israel in the past, and a high-rise office building housing Hamas-affiliated media offices, but also Agence France-Presse.

AFP reporters said they evacuated their fourth-floor office Tuesday, after an initial strike targeted sixth-floor offices linked to Hamas and other smaller factions.

A 4-year-old boy was killed in the second attack on the high-rise Wednesday, Gaza health official Ashraf al-Kidra said. The boy, Abdel-Rahman Naim, was in his family apartment in the building when he was struck by shrapnel and died on the way to Gaza's Shifa Hospital, al-Kidra said.

Washington blames Hamas rocket fire for the outbreak of violence and has backed Israel's right to defend itself, but has cautioned that an Israeli ground invasion could send casualties soaring.