Hamas has agreed to observe a 24-hour humanitarian truce after initially rejecting such an offer by Israel.