Christopher Wray, then assistant attorney general, in 2005. CreditLawrence Jackson/Associated Press

WASHINGTON — President Trump said Wednesday that he had selected the former federal prosecutor Christopher Wray, now a Washington-based criminal defense lawyer who recently represented Gov. Chris Christie of New Jersey in the so-called Bridgegate scandal, to be his new F.B.I. director.

The president revealed his decision in a morning tweet.

His announcement came a day before the former F.B.I. director James B. Comey was to testify about Mr. Trump’s attempts to get him to end the bureau’s investigation into his former national security adviser’s contacts with Russia. Mr. Trump’s news may represent an attempt to inject credibility into an investigation rocked by controversy and accusations of presidential tampering.

Mr. Wray is a safe, mainstream pick from a president who at one point was considering politicians for a job that has historically been kept outside of politics. Mr. Wray, a former assistant attorney general overseeing the criminal division under President George W. Bush, is likely to allay the fears of F.B.I. agents who worried that Mr. Trump would try to weaken or politicize the F.B.I.

Mr. Wray, two administration officials said, is a hybrid pick for Mr. Trump: He is a seasoned criminal lawyer, who bonded with Mr. Christie when both were young attorneys in the Justice Department, and a highly regarded criminal defense lawyer who represented Mr. Christie in the aftermath of the scandal over traffic jams that rocked his governorship.

That his political skills were honed in the crucible of scandal gave him an edge over the other finalist, John S. Pistole, the former deputy director of the F.B.I. and head of the Transportation Security Administration, the officials said. He managed to soothe and counsel the volatile Mr. Christie, a Trump ally.

Mr. Trump abruptly fired Mr. Comey, who had told associates that he felt the president was trying to influence him to drop inquiries that could affect him personally. The pick caps an extraordinary period in which Mr. Trump has been buffeted by his own shifting explanations for why he dismissed Mr. Comey, allegations that he shared highly classified information with top Russian officials in the Oval Office and the naming of a special counsel to oversee the investigation into his campaign’s possible ties with Moscow.

The decision was being closely watched not only for who will lead the nation’s premier law enforcement agency, where employees are still reeling from Mr. Comey’s firing, but also for signals about how the president will forge ahead amid the swirl of developments set off by the dismissal. Some Democrats have said impeachment proceedings should begin against him.

Mr. Trump met Tuesday with his two finalists, Mr. Wray and Mr. Pistole, the White House spokesman Sean Spicer said. The president had hoped to quickly pick a replacement for Mr. Comey before he embarked on his nine-day overseas trip in mid-May but was dissuaded from doing so by many of his top advisers, including Chief of Staff Reince Priebus and Donald F. McGahn II, the White House counsel.

Mr. Wray played a pivotal role in the aftermath of the Sept. 11, 2001, terrorist attacks, providing oversight of operations as the country adjusted to a new reality. As head of the criminal division from 2003 to 2005, he directed efforts to deal with fraud scandals plaguing the corporate world.

Mr. Trump, who fired Mr. Comey without having put in motion a plan to find his successor, conducted a whirlwind search, at one point zeroing in on Joseph I. Lieberman, the former Democratic senator and vice-presidential nominee, as a preferred finalist, even as he considered F.B.I. veterans including Adam S. Lee, the special agent in charge of the bureau’s Richmond, Va., field office; Richard A. McFeely, a former senior official; and Andrew G. McCabe, the acting director. Mr. Lieberman later withdrew from consideration.

It was during an interview with one of the prospective candidates at the White House that Mr. Trump received word of the appointment of the special counsel, Robert S. Mueller III, himself a former F.B.I. director, reflecting the crisis atmosphere that pervaded the president’s selection process and the stakes involved.

Others on Mr. Trump’s list had been former Gov. Frank Keating of Oklahoma and former Representative Mike Rogers of Michigan, both Republicans. Mr. Rogers, a former F.B.I. agent, was endorsed by the agents’ association.

Before joining the leadership of the Justice Department in Washington in 2001 as an associate deputy attorney general, Mr. Wray served as a federal prosecutor in Atlanta.

Mr. Wray graduated from Yale University in 1989 and earned his law degree in 1992 from Yale Law School.