Former FBI director James B. Comey on Wednesday defended the bureau’s 2016 investigation into possible coordination between the Trump campaign and Russia, pushing back on Senate Republicans’ skeptical questions about the probe and taking particular aim at Attorney General William P. Barr’s assertion that it was unfounded.

Testifying before the Republican-controlled Senate Judiciary Committee as part of that panel’s latest review of the Russia probe, Comey repeatedly told GOP lawmakers he disagreed with the “preamble” to their questions and expressed unfamiliarity with recently released information that they claim discredits the investigation.

He grew particularly exasperated when asked about Barr’s criticism that the FBI’s decision to open the investigation into the 2016 Trump campaign was based on insufficient evidence, saying he had “no idea what on earth” the attorney general was talking about.

“This was an investigation that was appropriately predicated and that had to be opened, and it was in the main, conducted in the right way,” he said, noting the investigation had produced charges against dozens of people. “The notion that the attorney general believes that was an illegitimate endeavor to investigate mystifies me.”

Later in the hearing, Comey suggested Barr was acting as if he were Trump’s “personal lawyer,” adding, “It ought to be a concern for all of us, because we need that institution, and we need that institution to be seen as separate from our tribal warfare.”

Asked to respond to Comey’s comments on Barr, Kerri Kupec, a Justice Department spokeswoman, said, “That’s obviously rich.”

Comey, a frequent target of attacks by Trump, is the third high-level official who supervised the Russia investigation to testify before the committee in recent months. In August, the committee heard testimony from former deputy attorney general Sally Yates, and in June, it summoned former deputy attorney general Rod J. Rosenstein, who succeeded Yates in the Justice Department’s No. 2 position.

The inquiry is being driven by Sen. Lindsey O. Graham (R-S.C.), a staunch Trump ally who has set out to uncover what he sees as impropriety in the investigation that would ultimately be taken over by special counsel Robert S. Mueller III.

Democrats have criticized the effort as a politically motivated attempt to undermine a probe that has dogged Trump’s presidency.

In addition to Senate Republicans’ work, U.S. Attorney John Durham in Connecticut is exploring the origins of the FBI’s Russia probe as part of a special assignment from Barr.

Comey appeared via video for about four hours, wearing a patterned blazer and a collared shirt, with no tie. While he conceded the bureau made some missteps in the case, he said, “Overall, I’m proud of the work.”

Democrats expressed alarm that the panel was focused on settling the scores of the last presidential election less than five weeks before the next one.

“We’re going back on a trip down memory lane to four years ago, to decide whether certain documents were handled properly and I will concede the fact that some were not,” Sen. Richard J. Durbin (D-Ill.) said. “Let’s be honest: If we were doing our job, we would be talking about the 2020 election.”

Sen. Cory Booker (D-N.J.) asked Comey to address Trump’s refusal at Tuesday night’s presidential debate to condemn white supremacy, and his telling the far-right Proud Boys group to “stand back and stand by.” Comey said America has long been plagued by a racist “radioactive stew” that it has controlled for decades with law and culture.

“When the president of the United States starts talking in that way, about that kind of group, he’s pulling out of that radioactive stew the control rods that we’ve used for 50 years to suppress racist violence,” Comey said. “It is a deeply disturbing development.”

Similarly, Democrats sought to have Comey highlight Trump’s unusual posture toward Russia and its leader, and what they see as evidence that nation could have financial leverage over the president. While Comey said he could not say whether Trump had been compromised, he noted, “It’s difficult to explain his conduct, his statements, in any other way, especially his refusal to criticize Vladimir Putin, even in public.”

Comey led the FBI when it first launched the investigation into Trump’s campaign in 2016, and his firing by Trump in 2017 escalated its stakes significantly. After Comey was forced out, then-acting FBI director Andrew McCabe, who had been Comey’s deputy, authorized agents to begin exploring Trump personally as a potential counterintelligence threat who had attempted to obstruct justice. Trump has said he was thinking of the Russia case when he removed Comey from his position.

Comey’s actions already have faced significant scrutiny, including from the Justice Department inspector general, who in late 2019 issued a report concluding the bureau had an “authorized purpose” to launch an investigation into Trump but blasting officials for other failures along the way.

Inspector General Michael Horowitz took aim in particular at the FBI’s controversial surveillance of former Trump campaign adviser Carter Page, accusing officials of filing error-laden applications to the Foreign Intelligence Surveillance Court to continue the monitoring after it likely should have stopped.

The inspector general found that Comey certified the bureau’s first three applications to surveil Page. While he found “no evidence” Comey was made aware of some of the problems, Horowitz said that was in part because “limited recollections and the absence of detailed documentation of meetings” made it difficult to determine what top FBI leaders were told by subordinates.

Comey conceded Wednesday that, if he knew then what he knows now, he would not have certified the applications without more discussion. He repeatedly professed ignorance about some of the information underlying the applications, though said that as the FBI leader, errors were “my responsibility.”

“I’m not looking to shirk responsibility,” he said. “The director is responsible.”

In his opening statement, Graham said the missteps with Page had put in jeopardy renewal of the Foreign Intelligence Surveillance Act, which gives the FBI power to secretly apply to a court to monitor suspected national security threats.

“This is not just an abuse of power against Mr. Page and the Trump campaign,” Graham said. “This is a system failure, and you could be next.”

Graham sought to hammer Comey on why exculpatory information about Page was not included in court applications, or relayed to Comey.

“How could all that happen and not get up to you, the director of the FBI, of one of the most important investigations in the history of the FBI?” Graham asked.

“I can only speculate, because it didn’t,” replied Comey, who repeatedly pushed back on Graham’s characterizations of the bureau’s missteps in the Page case.

Sen. Patrick J. Leahy (D-Vt.) ripped Graham for what he said was a politically motivated misuse of the committee’s time.

“I think it’s offensive to all Americans who pay taxes,” he said, adding, “I realize the president does not.”

Graham pressed Comey on information recently released by the Justice Department showing that a key source of allegations against the president had been previously investigated as a possible Russian asset and that an FBI agent assigned to investigate former Trump national security adviser Michael Flynn had misgivings about the case.

Christopher Steele, a former British intelligence officer who was hired by an opposition research firm working for the Democratic National Committee and Hillary Clinton’s campaign to investigate Trump, relied on that source as he assembled a dossier of allegations against the Trump campaign, and the bureau would ultimately rely on Steele’s information in applying to surveil Page.

The inspector general, though, found inconsistencies between what Steele claimed the source had told him and what the source told the FBI. It was not clear what Comey knew of that. According to the inspector general, while Comey was aware the FBI had interviewed the source, he was not given an intelligence memo detailing the discrepancies between his and Steele’s accounts.

Comey told Graham, “I don’t remember anything about interviews of the subsource.” He said the FBI agent who investigated Flynn seemed to be “confusing the nature of the investigation.”

On Tuesday, Graham shared newly declassified information showing that U.S. intelligence agencies learned in late July 2016 that a Russian intelligence analysis claimed Clinton had approved a campaign plan to “stir up” a scandal against Trump by tying him to Putin and the hacking of the Democratic National Committee. It’s unclear if the assertion by Russian intelligence is accurate, but by that point senior Clinton campaign officials had already publicly contended Trump was pushing pro-Russian policies and that Russia was behind the leaking of Democrats’ hacked emails.

Comey said Wednesday he had “trouble understanding” the information, which was described in a released letter from Director of National Intelligence John Ratcliffe.

“I really don’t know what he’s doing,” Comey said of Ratcliffe.

Tom Mentzer, a spokesman for Sen. Dianne Feinstein (Calif.), said Democratic staff for the Judiciary Committee was blocked from attending a classified meeting with Ratcliffe on Tuesday, where he briefed Graham’s staff on the substance of the four-year-old Russian analysis.

McCabe is scheduled to testify before the committee Oct. 6, though McCabe’s lawyer alleged in a letter to the inspector general that the FBI was refusing to give him access to personal notes and calendars from his time in the bureau that might help him refresh his recollection of events. The lawyer, Michael R. Bromwich, said McCabe had agreed to testify only if the committee would facilitate him accessing the materials and asked the Justice Department inspector general to investigate.

A spokesman for McCabe declined to say if he would testify Oct. 6.

Ellen Nakashima contributed to this report.