The agent, Peter Strzok, was removed in July from the investigation being run by special counsel Robert S. Mueller III, who is looking into possible coordination between Trump associates and Russian agents during last year's election.
Strzok, the top agent on that probe, was removed after supervisors learned he exchanged pro-Clinton, anti-Trump texts with a senior FBI lawyer with whom he had an affair, according to people familiar with the matter.
Strzok's alleged conduct is now the subject of a probe by the Justice Department's inspector general. Lawmakers tried to make Wray explain exactly what Strzok's role was in the Trump and Clinton investigations, but Wray declined to provide an answer, citing the ongoing investigation.
The revelations about Strzok prompted Trump to tweet this past weekend that the FBI's reputation was in tatters.
Asked by the panel's senior Democrat, Rep. Jerrold Nadler (D-N.Y.), whether that was true, Wray delivered a lengthy defense of the bureau.
"Congressman, there is no shortage of opinions out there. What I can tell you is that the FBI I see is tens of thousands of agents, analysts and staff working their tails off keeping Americans safe," Wray said. "The FBI that I see is people, decent people, committed to the highest principles of dignity and professionalism and respect. . . . Now do we make mistakes? You bet we make mistakes, just like everybody who's human makes mistakes.''
He said that once the inspector general's review of FBI conduct has concluded, "we will hold our folks accountable, if that's appropriate."
Wray became FBI director four months ago after Trump fired Wray's predecessor, James B. Comey, leading to Mueller's appointment as special counsel.
At the White House on Thursday, press secretary Sarah Huckabee Sanders said there was no discrepancy between the president's criticism and Wray's defense of the FBI. "We agree with Chris Wray that FBI field agents are appreciated and respected. The president's issues are with the political leaders in the FBI under former director Comey, particularly those that played politics with the Hillary Clinton email probe."
Republicans at the hearing said Wray needed to prove to them that the FBI was proceeding without picking political favorites.
"It does appear to me that, at the very least, the FBI's reputation as an impartial, nonpolitical agency has come into question," said the panel's chairman, Rep. Bob Goodlatte (R-Va.). "Even the appearance of impropriety will devastate the FBI's reputation."
Goodlatte and other Republicans are pressing the Justice Department to appoint a second special counsel to investigate the FBI's handling of Clinton-related matters, including an investigation into her use of a private email server when she was secretary of state.
Nadler warned Wray that he was under attack from Republicans and urged him to publicly rebut criticism from the president.
"I predict that these attacks on the FBI will grow louder and more brazen as the special counsel does his work and the walls close in around the president," Nadler said. "Your job requires you to have the courage in these circumstances to stand up to the president.''
Much of the early questions at the hearing concerned Strzok, a senior agent who played a central role in the FBI's Russia investigation until late July, when Mueller learned of the messages and removed him from the case.
Strzok's communications with senior FBI lawyer Lisa Page are now being investigated by the Justice Department's inspector general. Page had also worked on Mueller's team, but she left that post two weeks before Strzok's departure for what officials have said were unrelated reasons.
In a remarkable moment, Rep. Louie Gohmert (R-Tex.) read aloud from a list of FBI officials, asking Wray after each name whether that person had shown political bias in their work. After every name, Wray vouched for the person's character, though he acknowledged he did not know everyone Gohmert named.
Rep. Jim Jordan (R-Ohio) said he suspected that Strzok played a central role in requesting surveillance of people close to Trump, adding, "If that happened, that is as wrong as it gets."
In the wake of revelations about Strzok, conservative lawmakers and activists have intensified their attacks on the FBI, saying his alleged conduct and other issues, such as political donations by lawyers working under Mueller, show the probe is biased against the president. Law enforcement officials note that Mueller is a registered Republican and has been praised for more than a decade as one of the most trusted law enforcement officials in the country.
Democrats defended the FBI from Republican attacks. They also got assurances from Wray that no one was trying to interfere with Mueller's work.
"As I sit here today, there's been no effort that I've seen to interfere with Special Counsel Mueller's investigation," Wray said, adding that Trump called him once to congratulate him on the day of his installation as FBI chief but that he has not had any "substantive" one-on-one conversations with the president.
Wray has inherited the political fallout over the Clinton and Trump probes, and he has tried to keep a low profile and steer the agency clear of public political fights. Thursday's hearing made clear that his task is getting harder.
Rep. Ron DeSantis (R-Fla.) said Wray was "walking into contempt of Congress" after the director repeatedly declined to answer questions about Strzok.
And while some Republicans have called for a second special counsel to investigate FBI conduct, others have argued that Mueller's probe should be shut down or given a time limit to complete its work. Democrats attacked Republicans for suggesting unethical conduct had infected the decision-making process at the FBI.
Rep. Ted Deutch (D-Fla.) said Thursday's hearing showed the need to pass legislation protecting Mueller from being fired.
Some Republicans on the panel picked bigger fights with Wray, criticizing how the FBI conducts surveillance and threatening to vote against renewal of a legal authority due to expire at the end of this year. Wray has made renewal of that authority, called Section 702, a main legislative priority — intelligence officials have long considered it a critical investigative tool to detect and disrupt nascent terrorist plots as well as to gather foreign intelligence.
Rep. Ted Poe (R-Tex.) heaped scorn upon the FBI's arguments for the authority, accusing the bureau of withholding key information about how the program works.
Using a mocking tone, Poe said he has been told: " 'It's classified. I can't tell you that.' " Poe said that if he was not given further details about Section 702 surveillance, he would vote against its renewal.
Wray said the FBI regularly shares information with congressional intelligence committees.
At times, Wray sought to turn the conversation away from the current and past probes and talk instead about future threats. He said the department several months ago set up a "foreign influence" task force made up of agents from the cyber, counterintelligence and criminal divisions to "sniff out" efforts to interfere with the 2018 elections.
Josh Dawsey contributed to this report.