WASHINGTON — From his first days in office, President Trump repeatedly put pressure on his F.B.I. director, James B. Comey. He demanded loyalty. He asked that an investigation into an adviser be dropped. And he implored Mr. Comey to publicly clear his name.

As Mr. Comey described Wednesday in written testimony prepared for the Senate Intelligence Committee, Mr. Trump’s entreaties continued for months, in unexpected phone calls and awkward meetings. As Mr. Comey’s discomfort grew, so did the president’s persistence and his frustration with Mr. Comey’s unwillingness to help.

Mr. Trump fired Mr. Comey last month, and his account offered an extraordinary back story, one that unfolded with cinematic detail, terse dialogue and tense moments across a White House dinner table.

Mr. Comey is scheduled to deliver the testimony on Thursday at a Senate hearing that is shaping up to be the most dramatic moment so far in the tangle of congressional and F.B.I. investigations into Mr. Trump’s associates and possible collusion with Russian operatives during the 2016 election.