Rival Palestinian factions agree to restore calm