The Egyptian-sponsored deal delivered key achievements for all involved. It promised to halt years of Palestinian rocket attacks on southern Israel and ease border closings that have stifled Gaza's economy, and it affirmed the emergence of Egypt's new Islamist government as a key player in a changing region. But vague language in the agreement and deep hostility between the combatants made it far from certain that the bloodshed would end.
News of the truce, announced in Cairo and reached after furious diplomacy that drew in U.S., U.N., European and regional diplomats, set off ecstatic celebrations in Gaza, where thousands poured into the streets, firing guns into the air, honking horns and waving Palestinian, Hamas and Egyptian flags.
In Israel, small demonstrations were held in communities that were struck by rockets. Protesters said the military should have hit Hamas harder and some held signs demanding security and denouncing "agreements with terrorists."
Leaders on both sides used tough language as they prepared to engage in indirect negotiations on a future border arrangement through Egyptian mediators.
"I know there are citizens that expected a wider military operation and it could be that it will be needed. But at this time the right thing of the state of Israel is to take this opportunity to reach a continuous cease-fire," Israeli Prime Minister Benjamin Netanyahu said.
At a news conference in Cairo, the top Hamas leader in exile, Khaled Mashaal, claimed victory, saying the Israelis "failed in their adventure" and that Israel is "inevitably destined for defeat."
U.S. Secretary of State Hillary Rodham Clinton called it "a critical moment for the region."
"Egypt's new government is assuming the responsibility and leadership that has long made this country a cornerstone of regional stability and peace," Clinton said.
Israel launched its military offensive in Gaza on Nov. 14 in to halt months of renewed rocket fire from Gaza. In a first salvo, it assassinated the Hamas military chief, then bombarded more than 1,500 targets in eight days of airstrikes and artillery attacks. Palestinian militants led by Hamas showered Israel with more than 1,500 rockets, including longer-range weapons that reached as far as Jerusalem and Tel Aviv.
The fighting killed 161 Palestinians, including 71 civilians, and forced hundreds of thousands of people on both sides of the border to remain huddled indoors. Five Israelis were killed. It was the worst bloodshed since an Israeli invasion of Gaza four years ago that left hundreds dead.
Under the agreement, Egypt will play a key role in maintaining the peace. The U.S. also pledged engagement.
"In the days ahead, the United States will work with partners across the region to consolidate this progress, improve conditions for the people of Gaza, and provide security for the people of Israel," Clinton said at a joint news conference in Cairo with her Egyptian counterpart, Mohammed Kamel Amr.
By agreeing to the cease-fire, both Israel and Gaza's Hamas rulers stepped back from the brink of what could have been a full-fledged war. Both had compelling reasons to accept the Egyptian deal, even though its outlines are vague.
Israel, which had massed thousands of troops along the Gaza border, was warned by its Western allies, including the U.S., against launching a ground offensive. Hamas would likely have lost popular support if Gazans had to endure another devastating military invasion.
Hours before the deal was announced, a bomb exploded on a bus in Tel Aviv near Israel's military headquarters, wounding 27 people and raising fears of a breakdown in the diplomacy. The blast, which left the bus charred and its windows blown out, was the first bombing in Tel Aviv since 2006. The bomb was placed inside the bus by a man who got off, said Yitzhak Aharonovich, Israel's minister of internal security. It was not immediately clear who was behind the attack.
The deal calls for an immediate halt to "all hostilities," and after a 24-hour period of calm, talks will open on border arrangements. Gaza's Rafah border crossing with Egypt is expected to assume a central role in the talks. Largely limited to foot traffic, Hamas hopes to turn the crossing into a bustling trade zone.
The new negotiations will try to tackle some difficult issues. Israel will be seeking guarantees for a halt in weapons smuggling by Hamas. The Islamists want unrestricted movement and trade in and out of Gaza.
Israel imposed its blockade five years ago, after Hamas seized control of Gaza from the rival Fatah movement of President Mahmoud Abbas. Although the blockade has gradually been eased, key restrictions remain on exports, the entry of key raw materials, and the movement of people in and out of the area. These restrictions have ground Gaza's economy to a halt, fueling unemployment of more than 30 percent.
The negotiations will be laden with obstacles, and Egyptian mediators will be faced with tough-to-bridge positions by both sides. Hamas is likely to resist Israeli demands to demilitarize.
In his comments Wednesday, Mashaal boasted of the arsenal Hamas had amassed, both through a homegrown weapons industry and support from Iran, Israel's archenemy.
"We thank Iran for its support along with all the other nations that supported us," he said.
Mashaal said Hamas would demand a package that ends Gaza's isolation. "We talked about the crossings, and the freedom of movement and cargo," he said.
By brokering the truce, Egyptian President Mohammed Morsi emerged as a pivotal player in the new Middle East, which has been swept by Islamist fervor during the Arab Spring changes of the past two years. As the key sponsor of the deal, serving as a middleman in cases of truce violations, Morsi will continue to play a key role.
His Muslim Brotherhood is the parent movement of Hamas, and the Egyptian leader has sympathized with the Palestinian Islamic group.
However, he has largely kept in place the restrictions on the Gaza-Egypt border that were imposed five years ago by his pro-Western predecessor, Hosni Mubarak, when Israel began sealing Gaza. Only Gazans fitting certain criteria can enter Egypt, and Morsi has resisted Hamas demands to open a cargo crossing.
Morsi has continued Mubarak's policy, in part, because of Egyptian concerns that an open border between Gaza and Egypt would allow Israel to "dump" the territory onto Egypt and undermine Palestinian statehood dreams.
Gaza and the West Bank flank Israel, which prevents virtual all travel between the two territories. If Gaza is open to Egypt, this would deepen the Palestinian territorial division and further undermine Abbas.
In closed meetings with Egyptian intelligence officials, Israel expressed concern about weapons entering Gaza from Libya and elsewhere.
Egyptian officials responded that they are keen on stopping the flow of weapons, which affect security in the Sinai Peninsula and end up in militants' hands there, according to Egyptian intelligence officials present in the meetings. The officials spoke on condition of anonymity because they were not authorized to release the information.
The deal offered key accomplishments to both Israel and Hamas. By bringing quiet to Israel's embattled south, Netanyahu is likely to enjoy a boost of popularity just as he prepares to seek re-election in January.
Hamas' ability to stand up to Israel, combined with the international recognition it has gained, solidifies its control of Gaza, prolonging the rule of a militant group pledged to Israel's destruction.
After more than five years of political isolation, Gaza became a magnet for foreign leaders during the past eight days. The prime minister of Egypt, the foreign minister of Turkey and foreign ministers of several Arab countries visited Gaza to show their support for Hamas.
More importantly, both Israel and the U.S. engaged in negotiations with the Islamists, albeit indirectly. Both countries consider Hamas to be a terrorist group.
The biggest loser appears to be Abbas, the main political rival of Hamas, who was forced to watch the events in Gaza from the sidelines. Since losing control of Gaza, Abbas has been unable to end the bitter rift with Hamas, leaving him governing in the West Bank only. Abbas seeks an independent state that includes both territories.
The events of recent days, coupled with a four-year impasse in peace efforts with Israel, will underscore Abbas' image as an ineffective leader.
As the streets of Gaza City snarled with celebrations, chants of "God is great!" echoed from mosque speakers.
"I came out from under the fire. I want my children and I to live in safety. I don't want war," said Abdel-Nasser al-Tom, a resident of northern Gaza who had huddled for shelter in a U.N. school. "I just hope they commit to peace."
Federman reported from Jerusalem. Mohammed Daraghmeh in Cairo and Ariel David in Tel Aviv contributed to this report.