WASHINGTON — Atty. Gen. William Barr on Tuesday aggressively defended the federal response to violence and protests at the federal courthouse in Portland, Ore., and his decision to intercede in criminal cases involving President Trump’s close associates.

The attorney general’s highly anticipated appearance before the House Judiciary Committee lasted a contentious five hours as he parried attacks by Democrats over his response to nationwide protests against police violence, his handling of the Russia investigation and his skepticism about the security of voting by mail.

The bitter and partisan back-and-forth between the nation’s top law enforcement official and Democrats came as authorities have engaged in violent clashes with protesters outside the federal courthouse in Portland, unrest that escalated after federal officers were captured on video taking people into custody without apparent probable cause and driving them away in unmarked vans. Barr has dispatched dozens of federal officers to protect the building.

“Every night for the past two months, a mob of hundreds of rioters has laid siege to the federal courthouse and other nearby federal property,” Barr told the House Judiciary Committee.

“The rioters arrive equipped for a fight, armed with powerful slingshots, Tasers, sledgehammers, saws, knives, rifles and explosive devices. Inside the courthouse are a relatively small number of federal law enforcement personnel charged with a defensive mission: to protect the courthouse.”

“Since when is it OK to try to burn down a federal court?” he demanded, saying that federal agents were taking the necessary steps to protect federal property, particularly in Portland.

Local officials in Portland say that the presence of federal law enforcement agencies in the city has been inflaming the situation, exacerbating the violence.

Democrats took Barr to task for several actions, including ordering the clearing of protesters outside the White House on June 1, so as to allow Trump to be photographed holding a Bible outside a historic church across the street. Nationwide protests, including those outside the White House, were sparked by the killing of George Floyd, a 46-year-old Black man who died in May after a Minneapolis police officer pinned him at his neck while he was begging for air.

Barr said he ordered the operation at Lafayette Square to expand the perimeter around the White House, not to facilitate a photo op for the president.

Republicans defended Barr’s handling of protests and praised him for trying to save federal property. They said he was taking necessary steps to combat rioters.

They urged him to continue his agency’s internal investigation into the origins of the federal inquiry into potential ties between the Trump campaign and Moscow. While then-special counsel Robert S. Mueller III found no evidence that the campaign colluded with the Russian government, his report documented how the president’s campaign team welcomed Russia’s offers of help and expected to benefit from it.

“I want to thank you for having the courage to say that we are getting politics out of the Department of Justice,” said Rep. Jim Jordan (R-Ohio), the ranking Republican member on the panel.

Democrats also attacked Barr for amplifying Trump’s conspiracy theories and seeking to instigate confrontations with protesters to help Trump’s campaign. And they chastised the attorney general repeatedly for not doing enough to address racism in policing and use-of-force policies.

Barr testified he did not believe police departments were generally tainted by deep-seated racism but understood why Black people felt they were often treated as “suspects first and citizens second.”

His insistence that police misconduct reflected isolated incidents rather than a systemwide problem drew rebukes from Democrats.

“The department is not doing enough to address issues of racism, bias and brutality in law enforcement,” said Rep. Karen Bass (D-Los Angeles). As head of the Congressional Black Caucus, Bass has led Democratic efforts to adopt legislation that would ban certain police practices, including chokeholds, nationwide and allow more lawsuits against police officers accused of misconduct.

Barr was put on the defensive for his handling of two cases involving associates of President Trump. Rep. Jerrold Nadler (D-N.Y.), the chairman of the committee, cited Barr’s efforts to reduce the potential sentence of Roger Stone, a close associate of the president and self-admitted dirty trickster, and to seek to throw out the guilty plea of Michael Flynn, the president’s first national security advisor, for lying to the FBI.

“Your tenure is marked by a persistent war against the department’s professional core in an apparent effort to secure favors for the president,” Nadler said.

In February, Barr ordered federal prosecutors to reduce their sentencing recommendation for Stone. Barr said their recommendation of seven to nine years in prison was excessive, and the career prosecutors resigned from the case in protest. A federal judge ultimately sentenced Stone to 40 months in prison, in line with the prison term Barr believed was justified.

“The judge agreed with me,” Barr repeatedly said as Democratic members of the committee pressed him on the Stone sentencing.

Trump ultimately commuted Stone’s sentence this month.

In response to questions from Rep. Eric Swalwell (D-Dublin) about Stone, Barr said he had not intervened in the sentencing of any other defendants since he took over as attorney general in February 2019. He said he did not see any reason to investigate the president’s commutation of Stone’s sentence even though Stone has implied in news interviews that he had information that could harm Trump.

The attorney general also supported the effort to throw out Flynn’s guilty plea to lying to federal agents about his conversations with a Russian diplomat during the presidential transition.

Barr said federal agents and prosecutors unfairly targeted Flynn. “The president’s friends don’t deserve special breaks and don’t deserve to be treated more harshly,” he said.

Flynn’s lawyers and prosecutors won a key appeals court ruling last month that ordered a federal judge to throw out the plea. The judge has asked the full appeals court to reconsider the order.

The attorney general further defended the Justice Department’s handling of politically charged cases by noting it has not charged any of Trump’s political foes with crimes.

“What enemies have I indicted?” Barr asked. “Can you point to one indictment you feel was unmerited?”

In a potential foreshadowing of fights over the results of the November presidential election, Democrats pressed Barr over whether he agreed with Trump that the election system was “rigged.”

“I have no reason to think it will be,” he said.

They also criticized Barr for raising concerns about the security of mail-in voting, though he has voted by mail at least twice in the last decade.

While acknowledging he had no evidence to back up a claim that foreign adversaries could wreak havoc by submitting thousands of counterfeit ballots, Barr said he believed it could still happen. “I have common sense,” he said.

“The problem we are facing is that the president has repeatedly sought to cast doubt on the security of mail-in ballots,” countered Rep. Mary Gay Scanlon (D-Pa.). “Saying the 2020 election could be rigged with millions of mail-in ballots being printed by foreign countries. You have repeated this disinformation.”

Democrats have been pushing to give voters more access to mail-in ballots to alleviate the risks of voting amid a pandemic; Trump and other Republicans have resisted such efforts, saying widespread voting by mail could invite fraud. Trump tweeted in May that mail-in voting would result in the “end of our great Republican Party.”

“That suggests the president is spreading disinformation about mail-in voting because he is afraid his party will lose,” Scanlon said.