Wray told the House Judiciary Committee his agents work hard "protecting the American people and upholding the rule of law in all 50 states and in about 80 countries around the world."
"Let me start by saying that it is for me the honor of a lifetime to be here representing the men and women of the FBI," he said. "There is no finer institution than the FBI and no finer people than the men and women who work there and are its very beating heart."
When asked about Trump's tweets over the weekend criticizing the FBI, Wray told Rep. Jerry Nadler, "there is no shortage of opinions out there."
"What I can tell you is that the FBI that I see is tens of thousands of agents and analysts and staff working their tails off to keep Americans safe from the next terrorist attack, gang violence, child predators, spies from Russia, China and North Korea, and Iran," he responded. "The FBI that I see is tens of thousands of brave men and women who are working as hard as they can to keep people that they will never know safe from harm."
FBI employees will be held accountable if "appropriate," Wray added.
"When we make mistakes, there are independent processes like that of the outside, independent inspector general that will drive and dive deep into the facts surrounding those mistakes," he said. "And when that independent fact finding is complete, we will hold our folks accountable if that is appropriate."
Trump on Sunday tweeted that the FBI's reputation was "in tatters" and the "worst in history," seizing on reports about possible bias from a former top bureau official.
After Trump's tweets, Wray sent a message to employees Monday, telling staff that they should "expect -- and welcome -- people asking tough questions."
"We find ourselves under the microscope each and every day -- and rightfully so. We do hard work for a living," Wray said, not mentioning the President specifically.
On 'tainted' FBI agents
Throughout the hearing, Republican lawmakers have seized on the actions of Peter Strzok, who led the investigation of the Clinton email server as the No. 2 official in the FBI's counterintelligence division.
He left the Mueller team this past summer
after an internal investigation found messages he sent that could be interpreted as showing political bias for Hillary Clinton and against Trump, according to US officials briefed on the matter.
Chairman Bob Goodlatte, R-Virginia, asked Wray about what he's doing to clear the ranks of the FBI by people "tainted" by bias.
"I think these matters are being looked at, as they should be, by somebody outside the FBI, and when those findings come to me, I will take appropriate action if necessary," Wray said, referencing the ongoing inspector general investigation. "The first thing I'm doing is respecting the outside independent investigations that are underway. ... My preference is to be one of these people who is not an act first and ask questions later guy."
Clinton email investigation
GOP Rep. Steve King, of Iowa, pressed Wray on the decision to change former FBI Director James Comey's statement on Clinton's email investigation to say Clinton had been "extremely careless" rather than "grossly negligent."
He was referencing how an early draft of a memo by Comey described the behavior of Clinton as "grossly negligent" for her handling of classified information, though Comey in his July 5, 2016, public statement didn't use that term.
Electronic records show Strzok changed Comey's earlier draft language describing Clinton's actions as "grossly negligent" to "extremely careless," sources said.
"Gross negligence is the language in the statute I believe," Wray said. "But I believe also that almost anybody who grabbed a thesaurus would say that gross negligence and extremely careless are pretty darn close to each other."