Mr. Comey’s unwillingness to be alone with the president reflected how deeply Mr. Comey distrusted Mr. Trump, who Mr. Comey believed was trying to undermine the F.B.I.’s independence as it conducted a highly sensitive investigation into links between Mr. Trump’s associates and Russia, the officials said. By comparison, Mr. Comey met alone at least twice with President Obama.
A spokesman for the F.B.I. declined to comment on Mr. Comey’s request. A Justice Department spokesman, Ian Prior, said that “the attorney general doesn’t believe it’s appropriate to respond to media inquiries on matters that may be related to ongoing investigations.”
The Justice Department typically walls off the White House from criminal investigations to avoid even the appearance of political meddling in law enforcement. But Mr. Trump has repeatedly interjected himself in law enforcement matters, and never more dramatically than in his private meetings with Mr. Comey.
“You have the president of the United States talking to the director of the F.B.I., not just about any criminal investigation, but one involving his presidential campaign,” said Matthew S. Axelrod, who served in senior Justice Department roles during the Obama administration and is now a partner at the law firm Linklaters. “That is such a sharp departure from all the past traditions and rules of the road.”
But that raises one of the questions Mr. Comey will have to answer in his testimony on Thursday. If he believed that Mr. Trump was trying to get him to end an investigation, why did he not tell anyone about it?
Mr. Trump’s defenders note that Andrew G. McCabe, the acting director of the F.B.I., has said that “there has been no effort to impede our investigation.” Current and former law enforcement officials say Mr. Comey kept his interactions with Mr. Trump a secret in part because he was not sure whom at the Justice Department he could trust.
F.B.I. officials were also unsure whether what Mr. Trump had done was a crime or how the conversation could ever be corroborated. So Mr. Comey kept the circle of officials at the F.B.I. who knew about his interactions with Mr. Trump small because he did not want agents and analysts working on the case to be influenced by what the president wanted.
Mr. Comey’s decision to keep his interactions with Mr. Trump a secret from the Justice Department were the latest example of how he set himself apart from the department throughout his tenure at F.B.I. director.
Several times during the F.B.I.’s investigation into Hillary Clinton’s personal email server last year, for example, Mr. Comey made decisions without the Justice Department’s knowledge or approval, often to the consternation of Loretta Lynch, then the attorney general. Mr. Comey has said he made those decisions to protect the independence of the F.B.I. — decisions that have been praised and criticized along partisan lines.
“In a legal sense, we’re not independent of the Department of Justice,” Mr. Comey told Congress last month. “We are spiritually, culturally pretty independent group, and that’s the way you would want it.”
Mr. Comey is also likely to be asked Thursday what he told Mr. Trump about the Russia investigation. Mr. Trump has told aides and said publicly that, on three occasions, Mr. Comey assured him that he was not under investigation.
Current and former law enforcement officials said that when the investigation was handed over last month to a special counsel, Robert S. Mueller III, Mr. Trump was not a target. But it is not clear what, if anything, Mr. Comey told the president about whether he was being investigated.
While Justice Department policy allows authorities to tell people whether they are the target of an investigation, prosecutors — not F.B.I. agents — handle such discussions. “We typically do not answer that question,” Mr. McCabe testified recently.
Former officials say Mr. Comey anticipated that the president might ask whether he was being investigated, and consulted his advisers on how to delicately sidestep the question. The officials were not aware of how Mr. Comey decided to answer.
When the Justice Department transferred the Russia investigation to Mr. Mueller, it gave him the authority to investigate whether the president broke any laws by attempting to obstruct the case or by firing Mr. Comey.
As F.B.I. director, Mr. Comey wrote a detailed memo after every major phone call or meeting with Mr. Trump and left those memos in the bureau’s files when he left. As special counsel, Mr. Mueller has access to those memos, but the F.B.I. declined a request from the Senate Intelligence Committee for copies of the memos, citing the ongoing investigation. It is unclear whether Mr. Comey still has copies of all of them or plans to read from them during his testimony.
According to people briefed on the memos, they describe not only what Mr. Trump said, but details such as his tone and where he was sitting. In one memo, Mr. Comey described a dinner with Mr. Trump at the White House a week after the inauguration in January. Mr. Trump asked Mr. Comey to pledge his loyalty but Mr. Comey refused.
Two weeks later, on Feb. 14, Mr. Trump kicked Vice President Mike Pence, Mr. Sessions and other senior administration officials out of the Oval Office so he could have his one-on-one conversation with Mr. Comey, according to people briefed on one of Mr. Comey’s memos.
It was in that conversation that Mr. Trump asked Mr. Comey to end the investigation into Mr. Flynn, and encouraged him to investigate leaks, the people said.
“I hope you can see your way clear to letting this go, to letting Flynn go,” Mr. Trump told Mr. Comey, according to the memo Mr. Comey wrote describing that meeting. “He is a good guy. I hope you can let this go.”
Asked Tuesday about Mr. Comey’s coming testimony, Mr. Trump replied, “I wish him luck.”