Israeli and Hamas officials reached a deal to exchange dead hostages' bodies for hundreds of Palestinian prisoners, extending the fragile ceasefire.