Hours after a bomb ripped through a bus in Tel Aviv, apparently sinking all hope of ending eight days of violence in Gaza, Hillary Clinton and Egyptian Foreign Minister Mohamed Kamel Amr announced a ceasefire between Israel and Hamas.
The deal came into effect at 9pm local time following a frantic final day of diplomacy in which Ms Clinton shuttled between Jerusalem, Ramallah and Cairo to help seal the seal.
Around 18 rockets were fired in the first 90 minutes of the ceasefire, but hours later it appeared as if it was being observed by both sides. The Israeli Prime Minister, Benjamin Netanyahu, had warned it might take some time to impose discipline on all the militant cells.
Diplomatic sources in Jerusalem indicated that an immediate truce, if it held, would be followed by a staged departure of some 60,000 Israeli troops deployed along the Gaza border, followed by a gradual lifting of the trade and passenger restrictions imposed by Israel on Gaza in return for the gradual disarming of militant groups in the Hamas-controlled enclave.
Details leaked to the Egyptian media said the ceasefire was a four-point plan under which Israel and the Palestinian groups both commit to cease all hostile activity in Gaza or around its borders, and Israel will lift border controls, easing restrictions on the movement of goods and people in and out of Gaza.
Both sides were quick to claim victory following the announcement. Mr Netanyahu said in a televised address that Palestinian militants "presumed that I would refrain from acting forcefully against them. They were wrong."
"In a conversation I had this evening with President Obama I agreed with him that it would be a good thing to give a ceasefire a chance in order to calm the situation and to enable the citizens of Israel to return the rhythm of their normal lives," he said.
Meanwhile, addressing reporters in Cairo, Hamas leader Khaled Meshaal declared: "The Israeli conspiracy has failed. They wanted to conduct an election campaign and they wanted to test Egypt."
He added: "In 24 hours we will see how the ceasefire is going and then we will see how to fulfill the demands of the Palestinian people to end the killings and assassination and allow the Palestinian people to live like any other people."
Announcing the ceasefire in the Egyptian capital, Ms Clinton pointedly praised the "responsibility and leadership" of Egyptian President Mohammed Morsi, who played a key role in applying pressure to Hamas, just as Barack Obama brought all his weight to bear on Israel. Celebrations in the streets of Gaza followed the announcement, with many emerging from homes they had rarely left throughout a week of air attacks on the densely populated territory.
In Gaza City, the mood was one of relief. Ayman al-Assawi, 45, whose brother Rahem was one of those killed, said: "The main thing is for the fighting to stop." More than 150 Palestinians have been killed, 42 of them children; five Israelis have lost their lives.
Some in the Hamas hierarchy had argued that a ceasefire deal that failed to include an end the blockade of Gaza would mean that Israel can maintain a stranglehold on the Palestinian territory. But the head of Hamas's military, Mohammed Diaf, is said to have persuaded them that the deal on offer could not be bettered for the time being.