Attorney General William P. Barr vigorously defended the federal response to nationwide protests and civil unrest in a combative congressional hearing on Tuesday where Democrats accused him and other Trump administration officials of suppressing protesters’ rights in an overly violent crackdown.The attorney general also insisted that he intervened in the criminal cases of President Trump’s allies Roger J. Stone Jr. and Michael T. Flynn to uphold the rule of law, not to do Mr. Trump’s bidding.Mr. Barr’s defenses punctuated an outright hostile election-season oversight hearing before the House Judiciary Committee. Democrats tried to portray him as a dangerous errand boy for the president. But Mr. Barr insisted he was trying to enforce the law against what he characterized as rioters using demonstrations as cover to commit crimes. He also said of the criminal cases that grew out of the Russia investigation that he wanted to be fair to Mr. Trump’s former advisers.“The president’s friends don’t deserve special breaks, but they also don’t deserve to be treated more harshly than other people,” he said. “And sometimes that’s a difficult decision to make, especially when you know you’re going to be castigated for it.”The five-hour hearing, Mr. Barr’s first on Capitol Hill in more than a year, grew increasingly heated as Democrats spoke over his attempts to respond to their accusations. At one point, the attorney general exclaimed, “I’m going to answer the damn question.”Democrats were clearly angered as Mr. Barr quibbled over small details or ignored questions about his rationale or actions. But amid frequent sniping, lawmakers came away with few, if any, new facts or admissions.Democrats have sought to hold Mr. Barr to account since he presented a summary last year of the then-secret findings of the special counsel, Robert S. Mueller III, that a federal judge later said was “distorted” and “misleading” in a way that torqued public understanding of its findings in Mr. Trump’s favor.But Mr. Barr — who did not testify before the House Judiciary Committee when he was attorney general the first time, under President George Bush — had repeatedly put off requests to appear before the committee, saying he was too busy. In the meantime, lawmakers accumulated a long list of additional grievances that they aired on Tuesday.“You have aided and abetted the worst failings of the president,” Representative Jerrold Nadler of New York, the committee chairman, said at the start of the hearing to Mr. Barr, who sat impassively.Democrats charged that Mr. Barr had intervened improperly in the Stone and Flynn cases to please Mr. Trump. They accused him of helping the president promulgate bogus fears about voter fraud to help shake confidence in November’s election. And they warned that under Mr. Barr’s leadership, the Justice Department was trampling on the civil liberties of citizens like those demanding that the nation eradicate institutionalized racism against Black Americans.“The president wants footage for his campaign ads, and you appear to be serving it up to him as ordered,” Mr. Nadler said. “You are projecting fear and violence nationwide in pursuit of obvious political objectives. Shame on you, Mr. Barr.”The attorney general denied the charges, arguing at first calmly and then more irritably that federal agents confronting protesters were not trying to quash peaceful expressions of free speech, but to deal with “mob” violence.“Rioters and anarchists have hijacked legitimate protests to wreak senseless havoc and destruction on innocent victims,” he said.In particular, he defended the deployment of federal agents in Portland, Ore., accusing the local police of essentially abandoning a federal courthouse as rioters and vandals “laid siege” to it, threatening the functioning of the court system.“What unfolds nightly around the courthouse cannot reasonably be called protests,” Mr. Barr said. “It is by any objective measure an assault on the government of the United States.”Local officials have accused federal agents of being heavy-handed and said their presence reinvigorated tensions that had been subsiding.While some protesters have been violent, many others have been peaceful and have included high school students, military veterans, off-duty lawyers and lines of mothers who call themselves the “Wall of Moms.” Video shows that in some cases, agents attacked protesters when there was no apparent threat, including the case of a Navy veteran whose hands were smashed by officers.Mr. Barr likewise defended the federal response to protests last month at Lafayette Square outside the White House, where law enforcement used pepper balls and smoke bombs to clear the area before Mr. Trump walked through to take a photograph in front of a nearby church. Mr. Barr said officials had reached a “consensus” that a protective perimeter outside the White House had to be extended because they wanted to prevent the vandalism of previous nights.“Do you think the response at Lafayette Square to tear gas, pepper spray and beat protesters and injure American citizens who were just simply exercising their First Amendment rights was appropriate?” asked Representative Pramila Jayapal, Democrat of Washington.Mr. Barr responded that “no tear gas was used” on the protesters but did not address the substance of the question. The United States Park Police has confirmed “the use of smoke canisters and pepper balls.”The Justice Department’s independent inspector general is investigating the actions of federal agents during the episode.Asked about the pleas for racial justice informing many of the protests, Mr. Barr said, “I don’t agree that there is systemic racism in police departments generally in this country,” and he quoted statistics that more white Americans had been killed by the police than Black Americans.Critics have called those figures misleading because they do not account for relative population differences; a Black person is more likely to be killed than a white person.Republicans backed the attorney general for showing “courage” by taking aim at the Russia investigation and attacks on the police.Their most visceral defense came in a five-minute video montage that appeared to show protesters or people infiltrating their ranks turning to violence. It began with footage of cable news anchors describing the protests as “peaceful” before streaming through scenes like a police precinct being set ablaze in Minneapolis, American flags burning, cans being hurled at the police and stores being looted.“I want to thank you for defending law enforcement, for pointing out what a crazy idea this defund-the-police policy, whatever you want to call it, is, and standing up for the rule of law,” Representative Jim Jordan of Ohio, the panel’s top Republican, told Mr. Barr before playing the video.Republicans cheered on Mr. Barr as he defended his decision to overrule career prosecutors in the Stone case, saying that they were trying to treat Mr. Stone more harshly than other defendants. The Judiciary Committee heard testimony from one of the prosecutors last month who accused department leaders of changing the sentencing recommendation for “political reasons.”“The line prosecutors were trying to advocate for a sentence that was more than twice what anyone else in a similar position had ever served,” Mr. Barr said. “This is a 67-year-old man, first-time offender, no violence, and they were trying to put him in jail for seven to nine years. I was not going to advocate that. Because that is not the rule of law.”But the prosecutors said in court that they arrived at the seven-to-nine-year recommendation by following the Justice Department’s own sentencing guidelines, as is customary in any federal criminal case. Questioned by the federal judge who oversaw the Stone case, department officials acknowledged that it was the policy of the United States attorney’s office in Washington to seek the harshest possible sentence under the sentencing guidelines and to let the judge decide whether it was warranted.Representative Ted Deutch, Democrat of Florida, later asked Mr. Barr repeatedly if he would point to any other case where the department had failed to recommended a punishment in line with the guidelines set out for a defendant like Mr. Stone, who had threatened a witness.Mr. Barr did not answer directly, insisting that “the judge agreed with me” because she gave Mr. Stone a lighter sentence than the prosecution team had recommended before he overruled them. Mr. Trump commuted Mr. Stone’s sentence this month.Asked about the criminal prosecutor, John H. Durham, reviewing the Russia investigation, Mr. Barr declined to commit to waiting until after the general election in November to release any report that Mr. Durham produced. Mr. Barr repeated his view that Justice Department policy against taking actions that could affect elections should apply to Mr. Durham’s work.Democrats also pressed Mr. Barr to justify his repeated warnings about the risk of increased mail-in balloting in the upcoming election because of the coronavirus pandemic. After Mr. Trump attacked such efforts and claimed that mail-in ballots would be used for fraud to rig the election against him — even though he himself has voted by mail — Mr. Barr suggested without evidence, including in interviews with The New York Times and Fox News, that there was a serious risk of foreign countries mass-counterfeiting ballots.Experts say that a foreign-sponsored plot to systematically tamper with ballots is nearly impossible because of how they are printed and tracked. Many states have conducted elections by mail for years without any major security problems or widespread fraud.Representative Cedric L. Richmond, Democrat of Louisiana, asked Mr. Barr whether he believed the presidential election would be rigged. The attorney general said he had no reason to think it would be, but then added, “If you have wholesale mail-in voting, it substantially increases the risk of fraud.”For all the grab-bag of policy issues raised by the questioning, the exchanges proved to be more heated than illuminating. At one point, Mr. Jordan — who is known for his bombastic style of questioning witnesses — complained that Democrats were talking over Mr. Barr.“For months you have tried to get the attorney general to come,” Mr. Jordan interjected. “He is here. Why don’t you let him speak?”“The gentleman’s rudeness is not recognized,” Mr. Nadler replied, trying to move on to the next lawmaker in line to question Mr. Barr.“Rudeness? Rudeness? Rudeness?” Mr. Jordan shot back. “Time after time, you refuse to let the attorney general answer the questions posed to him.”Sharon LaFraniere and Linda Qiu contributed reporting.