WASHINGTON — James B. Comey, the recently fired F.B.I. director, said Thursday in an extraordinary Senate hearing that he believed President Trump had tried to derail an investigation into his national security adviser, and accused the president of lying and defaming him and the F.B.I.

Mr. Comey, no longer constrained by the formalities of a government job, offered a blunt, plain-spoken assessment of a president whose conversations unnerved him from the day they met, weeks before Mr. Trump took office.

The James Comey who emerged during the hearing was by turns humble, folksy and matter-of-fact. But at the same time, he proved that underneath was a Washington veteran who understood how to tell his story for maximum effect.

In testimony to the Senate Intelligence Committee, he provided an unflattering back story to his abrupt dismissal and raised the question of whether Mr. Trump had tried to obstruct justice.