Senator Patrick J. Leahy, Democrat of Vermont, asked what Mr. Wray would do if the president requested that he take any steps that Mr. Wray believed were illegal.
âFirst, I would try to talk him out of it,â Mr. Wray said. âIf that failed, I would resign.â
He also said he had no doubts about the intelligence communityâs assessment that Russia interfered in the election, a conclusion the president has questioned. He pledged that if confirmed, he would read the classified portions of the assessment as soon as he was sworn in.
Mr. Wray also sought to separate himself from Mr. Comeyâs actions, including the former directorâs announcement last summer that he would not recommend charges in the investigation of Hillary Clintonâs handling of classified information. Mr. Comey had explained the move as an effort in part to maintain the F.B.I.âs political neutrality, but he was widely criticized for plunging the bureau into the middle of the presidential campaign. Former prosecutors criticized him for making public remarks about Mrs. Clintonâs behavior.
Pressed by Senator Lindsey Graham, Republican of South Carolina, on how he would have handled the investigation, Mr. Wray said he would not have held a news conference.
âIn my experience as a prosecutor and as head of the criminal division, I understand there to be department policies that govern public comments about uncharged individuals,â Mr. Wray said of the Justice Department. âI think those policies are there for a reason, and I would follow those policies.â
Mr. Wray added, âI canât imagine a situation where, as F.B.I. director, I would be giving a press conference on an uncharged individual, much less talking in detail about it.â
An animated Mr. Graham also touched on the dominant question in Washington since the election: whether associates of Mr. Trump were involved in Russiaâs meddling. He read aloud from the latest revelation to make headlines, emails that an intermediary sent in June 2016 to Donald Trump Jr., the presidentâs eldest son, promising damaging information about Mrs. Clinton furnished by the Russian government. He then asked Mr. Wray what politicians should do if they received such an offer, suggesting they call the F.B.I.
âAny threat or effort to interfere with our elections from any nation-state or any nonstate actor is the kind of thing the F.B.I. would want to know,â Mr. Wray said.
Mr. Graham, who has been critical of Russian interference in the election, described the response as a âgreat answer.â
Mr. Wray also seemed to eager to knock down any suggestion that while he was a top Justice Department official in the George W. Bush administration, he was involved in signing off on the C.I.A.âs torture of suspects during its hunt for the planners of the Sept. 11 attacks.
Mr. Wray said he played no role in approving the legal rationale for those interrogations, adding that he did not condone torture.
âThe F.B.I. is going to play no part in the use of any techniques of that sort,â Mr. Wray said. President Barack Obama barred the use of such interrogation techniques in 2009.
Mr. Wray said he would not duck his responsibilities to uphold the law. He pointed to his record of investigating C.I.A. abuses while he was running the Justice Departmentâs criminal division from 2003 to 2005. He said he was proud of prosecuting a C.I.A. contractor, David A. Passaro, who had been convicted of beating an Afghan farmer during an interrogation.
Mr. Wray said he had not talked with Mr. Comey in years, but he recounted a now-famous episode when he, along with Mr. Comey and Robert S. Mueller III, now the special counsel investigating the Russian meddling, considered resigning from the Justice Department. In 2004, Mr. Mueller, then the F.B.I. director, and Mr. Comey, who was the deputy attorney general, threatened to quit the Bush administration over a controversial surveillance program. Mr. Wray also offered to join their protest even though he was not read into the highly classified program.
âKnowing those people and having worked side by side with those people and knowing these were hardly shrinking violets in the war on terror, there was no hesitation in my mind as to where I stood,â he said. âI stood with them.â
Mr. Wray graduated in 1989 from Yale University and earned his law degree in 1992 from Yale Law School. He was hired as a federal prosecutor in Atlanta in 1997 and left the Justice Department in 2005 after rising to the head of the criminal division.
Friends and former colleagues describe Mr. Wray as low-key and understated but exceptionally smart and thoughtful. But Mr. Wray warned those listening to the hearing not to underestimate him because they might view him as âboring,â prompting nods among family members sitting behind him.
âAnybody who does would be making a very grave mistake,â he said. He added that he would resist any political pressure if confirmed.
âI fully understand that this is not a job for the faint of heart,â Mr. Wray said. âI can assure this committee, I am not faint of heart.â