Israel and Hamas agreed to a deal to halt fighting in Gaza and exchange Israeli hostages for Palestinian prisoners, an official briefed on the deal told Reuters on Wednesday, opening the way to a possible end to a 15-month war that has upended the Middle East.