Nearly everyone who knows him seems to agree that Rod Rosenstein, the Deputy Attorney General and the official overseeing the special counsel Robert Mueller’s investigation of links between the Trump campaign and Russia, has a reputation for integrity.

“Rod is a prosecutor, not a persecutor,” Jim Trusty, the former head of the Justice Department’s organized-crime division, who worked with Rosenstein when they were prosecutors in Maryland, said. “Whatever he ends up doing, it ain’t going to be a witch trial. He’s going to go where evidence takes him.”

A former senior Justice Department official in the Obama Administration told me, “Rod’s reputation, which he’s earned, is that he does things by the book.”

Rosenstein, who went to Wharton, like the President, and Harvard Law School, where he was the editor of the Law Review, was the longest-serving U.S. Attorney in the country when he was confirmed by the Senate, in April, as the No. 2 official at the Justice Department. It is rare for a U.S. Attorney to survive in his job when a White House changes parties. President Trump, for example, recently fired all the remaining Obama holdovers. But Rosenstein, who was appointed by George W. Bush, in 2005, to be a U.S. Attorney in Maryland, was kept in his post through Barack Obama’s entire Presidency. He had earned the support of Barbara Mikulski, a Democrat who was then the state’s senior senator, who by tradition Presidents often defer to. “Rod has proven to be an objective prosecutor for many years, and that’s why Democrats have let him stay in that position,” Trusty told me.

Despite the Democratic hostility that most Trump nominees attract, the Senate confirmed Rosenstein as Deputy Attorney General by a vote of ninety-four to six. But Rosenstein, somewhat like James Comey, the F.B.I. director whom he helped oust, suddenly finds himself in the unusual position of attracting the ire of both Democrats and Trump.

On Friday morning, in an astounding tweet whose intent many Justice Department watchers and friends of Rosenstein are trying to discern, the President of the United States attacked his own Deputy Attorney General.

“I am being investigated for firing the FBI Director by the man who told me to fire the FBI Director!” Trump tweeted at 9:07 A.M. “Witch Hunt.”

Rosenstein’s reputation for integrity began to fray in early May, when he made a fateful decision to share with the President and Jeff Sessions, the Attorney General, his honest thoughts about Comey. At a meeting in the White House that neither Sessions nor Rosenstein has publicly described in full, Trump reportedly asked Rosenstein to write a memo explaining the case for removing Comey as F.B.I. director. According to senators, Rosenstein later testified in a closed-door briefing that he knew before he wrote the memo that Trump would fire Comey.

The “FBI’s reputation and credibility have suffered substantial damage, and it has affected the entire Department of Justice,” Rosenstein wrote, explaining that Comey was wrong to “usurp the authority” of the Attorney General in the Hillary Clinton e-mail case. “As you and I have discussed, however, I cannot defend the Director's handling of the conclusion of the investigation of Secretary Clinton's emails, and I do not understand his refusal to accept the nearly universal judgment that he was mistaken.”

To Rosenstein’s friends and defenders, the content of the memo was not controversial. “A lot of prosecutors, whatever their political stripes, said Rod is right about the role of an investigator versus a prosecutor,” Trusty said. “Nobody should be getting up the way Comey did and saying, ‘Here are a bunch of offenses, but we’re not going to prosecute.’ ”

Trump immediately fired Comey and released the Rosenstein memo to the public to explain his decision. Democrats and many lawyers in Washington who had a high opinion of Rosenstein were shocked that he allowed himself to be used by Trump and Sessions in such a blatant scheme to oust the person investigating the President’s own campaign. Senator Chuck Schumer wrote to Rosenstein warning that the Deputy Attorney General had “imperiled” his reputation as an “apolitical actor.”

“The content of that memo is totally in keeping with Rod,” the former Obama official said. “He’s a by-the-book guy, and he was deeply offended by how Comey broke the rules. The thing I don’t understand is how Rod let himself get played like that.”

The fallout from Rosenstein’s Comey memo may have been the result of a clash between the two men’s distinguishing characteristics: Comey’s zealous self-regard for his own independence and Rosenstein’s adherence to the letter of the law and Justice Department guidelines. Rosenstein may have genuinely believed that he was correcting an egregious harm to the Justice Department committed by Comey, one that still offended many lawyers there.

And Comey may have made his own mistake. Before Comey was fired, he apparently never went to Rosenstein and explained the steps that Trump had taken to try to shut down the investigation of Michael Flynn. If Comey had, Rosenstein would have known that Trump was taking actions that looked a lot like obstruction of justice. “If Comey had gone to Rod, he would never have written that memo,” the Obama official said. “Those alarm bells should have gone off for Rod anyway, but Comey, by keeping it so close and feeling he’s not accountable to anyone, made it easier for Rod.”

But Trump and Sessions’s ploy backfired. Some observers suggested that Rosenstein felt used and betrayed by the President and Sessions. Whether Rosenstein was trying to correct a mistake or not, his actions since Comey’s firing have been widely commended. When he appointed Mueller as special counsel to oversee the investigation, Rosenstein’s statement announcing the decision was scrupulously fair to Mueller, the President, and Trump-campaign associates. “My decision is not a finding that crimes have been committed or that any prosecution is warranted. I have made no such determination,” he wrote. “What I have determined is that based upon the unique circumstances the public interest requires me to place this investigation under the authority of a person who exercises a degree of independence from the normal chain of command.”

In testimony this week, when rumors were spreading that Trump wanted to fire Mueller, Rosenstein, to whom Mueller reports, made it clear that he would not carry out Trump’s order to remove Mueller unless, as Justice Department guidelines say, there was “just cause.”

While Rosenstein has said that he has “no reservations about my role” in firing Comey, his actions to safeguard the independence of the investigation and publicly warn Trump that he would not obey an order to fire Mueller may have triggered Trump’s wrath on Friday morning. Ironically, Trump is now alluding to the fact that Rosenstein was—wittingly or not—a part of the plot to get rid of Comey. Trump may be seizing on that fact as a way to push Rosenstein into recusing himself from the Russia investigation. (Rosenstein has reportedly already raised the issue of recusal internally, at the Justice Department.)

It is classic Trump: he ensnared Rosenstein in a scheme to get rid of Comey. Now that Rosenstein has tried to correct his error and insulate the investigation from further meddling, Trump is using Rosenstein’s role in the scheme to try to push him aside. (If this sounds like a plot from “The Sopranos,” it’s because there were, in fact, several episodes like this.)

Rosenstein may have only himself to blame if he is sidelined from the investigation by recusal. Despite his mistakes, he is probably the best guarantor of a fair inquiry. (The next person in line, Rachel Lee Brand, the Associate Attorney General, has a background in Republican politics and little experience in criminal or national-security cases.) If Rosenstein is forced to recuse himself, whoever comes after him as Mueller’s overseer will know that Trump is hoping that he or she will be more pliable.