In extraordinary testimony, the fired F.B.I. director said the president had tried to undermine an investigation into an adviser.