Israel and Hamas have agreed to the "first phase" of a ceasefire deal intended to end to the devastating Gaza war that unleashed the deadliest fighting ever between Israelis and Palestinians.