Palestinians win deal with gunmen to save truce