Under the deal, Israel has agreed to end all hostilities and targeted killings, while Hamas will stop attacks against Israel and along the border.
At least 157 people have died since the flare-up of violence began last week.
Both sides continued to fire on each other as the 21:00 (19:00 GMT) ceasefire deadline approached, but no major breaches have been reported.
By Jeremy BowenBBC Middle East editor
As usual, the talking started before the killing stopped. Since Hamas took over internal control of the Gaza Strip from their Palestinian rivals Fatah in 2007, there have been many spasms of cross-border violence. All have been followed by ceasefires. All have fallen apart, and every time Israel and Hamas blame each other.
The reason is that the ceasefires have been, to paraphrase a spokesman for the Israeli prime minister, sticking-plaster solutions.  They cover up the fundamental problem which is that Hamas and Israel are in what amounts to a constant state of war. For months on end it can be a cold war, until it runs hot - and deadly - again.
There is a strong chance that a new ceasefire will eventually fall apart too, unless it brings with it a major change in the political equation between Israel and the Palestinians, especially those in Gaza.
This time round, both sides have been trying to change the rules of the game by attaching conditions to a ceasefire. Israel wanted Hamas not to rearm, and not to fire over the border. Hamas wanted Israel to stop assassinations and to stop the blockade of Gaza.
That's the kind of deal that might even work if they made it. But for that to happen, both sides would have to make big concessions to their enemy.
Earlier, a bomb exploded on a bus in the Israeli city of Tel Aviv, leaving three people needing surgery and several others with light wounds.
Wednesday also saw at least 13 people die in Gaza.
Palestinian gunmen fired into the air in Gaza in celebration after the deal was announced.
Israeli police said a handful of rockets were fired out of Gaza after the ceasefire but no injuries or damage were reported.
Israel has agreed to "stop all hostilities on the Gaza Strip, land, sea and air including incursions and targeting of individuals", the ceasefire deal says.
"All Palestinian factions shall stop all hostilities from the Gaza Strip against Israel, including rocket attacks and attacks along the border," it stipulates.
Hamas political leader Khaled Meshaal said Israel's offensive had "failed". He also thanked Egypt for brokering the deal, which he said met Hamas's main demands.
All the crossings into Gaza would re-open, including those with Egypt, Mr Meshaal said.
A statement from the office of Israeli Prime Minister Benjamin Netanyahu said he had agreed to a US suggestion "to give a chance to Egypt's proposal for a ceasefire and so give an opportunity to stabilise the situation and calm it before there will be need to apply greater force".
Egyptian Foreign Minister Kamel Amr announced the ceasefire at a news conference in Cairo with US Secretary of State Hillary Clinton, who joined negotiations on Wednesday.
For the truce to continue, Mrs Clinton said, "the rocket attacks [from Gaza] must end and a broader calm must return".
"Now we have to focus on reaching a durable outcome that promotes regional stability and advances the security, dignity and legitimate aspirations of Palestinians and Israelis alike," she added.
Meeting later, the UN Security Council urged both Israel and Hamas to "act seriously to implement [the ceasefire's] provisions in good faith" and urged the international community to provide emergency aid to Gaza.
Briefing the session from Tel Aviv, UN Secretary General Ban Ki-moon said: "There are many details that must be solidified for a broad, durable ceasefire to take firm hold over the longer term."
US President Barack Obama praised the Israeli leader for accepting the deal and said he would seek additional funding for the Iron Dome missile defence system, which destroyed more than 400 rockets from Gaza in mid-air during the past week.
He also thanked Egyptian President Mohammed Mursi for his efforts.
Ties between Hamas and Egypt have strengthened since Mr Mursi was elected earlier this year. Hamas was formed as an offshoot of the Muslim Brotherhood, to which Mr Mursi belongs.
Also on Wednesday, Palestinian militants fired more rockets at Israel, while Israel renewed its naval artillery bombardment of Gaza.
Israel launched its current offensive a week ago with the killing of Hamas military leader Ahmed Jabari.
The Israeli government says his assassination, and the subsequent offensive, were aimed at ending rocket fire from Gaza.
More than 150 Palestinians and five Israelis have since been killed.
Israeli officials described Wednesday's bus explosion as a "terrorist attack". Hamas praised it but has not said it was behind the blast.
A ceasefire between Israel and the Palestinian Hamas movement which governs Gaza has come into effect.