FBI Director Christopher A. Wray is trying to restore public confidence in the bureau’s tarnished image by staying out of the political fray even if it puts him at odds with a president and allies intent on turning the agency into a political punching bag.

Bureau watchers say Mr. Wray is trying to differentiate himself from his publicity-hungry predecessor James B. Comey while defending agents and other employees who have been buffeted by accusations of bias and poor investigative tactics surrounding the 2016 presidential election.

Confirmed in 2017, Mr. Wray has eschewed press conferences and has been far more circumspect in his appearances on Capitol Hill.

“I would say in light of the actions of the previous FBI director, Comey, Christopher Wray is appropriately trying to make the FBI director role less visible,” said Kevin Brock, a former FBI assistant director of intelligence.

But that reticence cuts both ways, including when he declined to back his boss, Attorney General William P. Barr, in referring to the FBI’s approach to the Trump campaign as “spying.”

Allies of the president have also slammed Mr. Wray for slow-walking requests for information about the activities of Mr. Comey, former FBI Deputy Director Andrew McCabe, and anti-Trump bureau employees Peter Strzok and Lisa Page.

“The Director is protecting the same gang that tried to overthrow the president through an illegal coup,” Mr. Trump tweeted.

Mr. Wray’s supporters urge him to ignore the president’s Twitter rage, saying comparisons to Mr. Comey are unfair.

They see a director trying to bring the bureau back from episodes in which it ended up investigating both the Republican and Democratic presidential nominees in 2016, and for which it is still facing multiple investigations over its decision-making.

As evidence, they point to the housecleaning at the bureau, with many of the main players in the 2016 investigations either retired or fired.

“Comey put the FBI in a political quagmire, and Wray is trying to dig the bureau out,” said Lew Schiliro, a former head of the FBI’s New York field office. “What Wray is doing now is attempting to establish the independence of the FBI outside of political influence, which is essential to its mission.”

Thomas J. Baker, who served as an FBI special agent for 33 years, agreed.

“I think Wray is making an effort to keep a low profile and keep the FBI out of any additional controversy, which I think at this point in its history is a good thing,” he said.

Rep. Devin Nunes of California, the top Republican on the House Permanent Select Committee on Intelligence, said Mr. Wray’s defense of his bureau has spilled over into obstruction of Republican efforts to get to the bottom of the origins of the broader investigation into Mr. Trump and Russian activities surrounding the 2016 election.

“Congressional Republicans on the intelligence committee and other committees repeatedly had to fight tooth and nail to overcome the FBI’s stonewalling and get access to crucial documents they didn’t want us to see. They act like they’re afraid — with good reason — about people discovering the full extent of the abnormalities and corruption surrounding the Russia investigation,” Mr. Nunes said.

Mr. Brock said he was happy to see that criticism from the right. He called it a healthy sign for the FBI.

“It shows the FBI’s role as an independent agency, with the director setting the tone,” the former agent said. “I think it’s incumbent upon the director to establish a healthy arms-length relationship with not only the White House but the Department of Justice.”

Mr. Wray’s biggest tests are likely still to come.

First, he will have to deal with the fallout from Justice Department Inspector General Michael Horowitz, who is expected to announce the findings this month of his investigation into how the FBI obtained a warrant to conduct surveillance on onetime Trump campaign figure Carter Page. That warrant, plus the FBI’s use of plants to try to get close to another campaign official, have fueled Mr. Barr’s suspicion of spying on the Trump campaign.

Mr. Wray will also have to decide how to handle a follow-up investigation Mr. Barr ordered by a U.S. attorney into the origins of the investigation into Mr. Trump and Russia.

Mr. Barr has not been shy about complaining that the FBI lost its way under President Obama. He placed the blame in an interview last week with CBS News at the top of the bureau.

“I think the activities were undertaken by a small group at the top, which is one of the, probably, one of the mistakes that has been made, instead of running this as a normal bureau investigation or counterintelligence investigation. It was done by the executives at the senior level, out of headquarters,” the attorney general told CBS.

Asked whether he was talking about Mr. Comey or former FBI Deputy Director Andrew McCabe, Mr. Barr declined to be specific.

“I’m just not going to get into the individual names at this point,” the attorney general said. “But I just view that — I don’t view it as a bureauwide issue. And I will say the same thing for other intelligence agencies. And they’re being very cooperative in helping us.”

Mr. Comey, who has become a remarkable political force after his exile from the FBI, denounced Mr. Barr’s appearance as conspiracy-mongering.

“Bill Barr on CBS offers no facts. An AG should not be echoing conspiracy theories. He should gather facts and show them. That is what justice is about,” Mr. Comey tweeted over the weekend.

Mr. Schiliro said the debate over whether the bureau spied on Trump campaign workers has distracted from the fact that Russia did try to meddle in the election and the FBI was obligated to investigate. Ultimately, special counsel Robert Mueller found insufficient evidence to accuse the Trump campaign of conspiring with Russia to influence the election.

“That the investigation spilled over into several people working on the Trump campaign has made Russian election meddling a tangential item,” he said. “The Mueller report makes it clear the bureau’s predication to open the investigation. The fact that Mueller couldn’t connect it to Trump or the campaign doesn’t mitigate the bureau’s responsibility to investigate.”