British PM resigns to avoid defeat