Mr. Trump summarily fired Mr. Comey in May, infuriating many F.B.I. agents who saw the move as disrespectful.

Since then, the bureau has been run by Andrew G. McCabe, the acting F.B.I. director, whom the president has attacked repeatedly because his wife, a Democrat, ran unsuccessfully for a seat in the Virginia Legislature. Mr. McCabe was also close to Mr. Comey and served as his deputy before the director was fired, fueling suspicions among the president’s closest aides.

With Mr. Wray confirmed, it is not clear what will happen to Mr. McCabe, who is eligible to retire in March. If Mr. Wray decides to keep Mr. McCabe as his deputy, it could prompt Mr. Trump’s ire, creating discomfort at the F.B.I. Yet demoting Mr. McCabe, a career F.B.I. agent, would probably anger other agents, who would see it as a move that placates the president.

Friends and former colleagues of Mr. Wray say he is a low-key leader but mindful of the divisions that should exist between the F.B.I. and the White House. At his Senate confirmation hearing last month, Mr. Wray said he would resist any political pressure. He told the Senate that he knew he was walking into a political maelstrom.

“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.”

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 as an assistant attorney general.