Israel and Hamas are finalizing an agreement for a phased cease-fire to end 15 months of brutal fighting in Gaza.