Trump has repeatedly criticized Comey for being too soft on Clinton. During the campaign, he said she should be locked up and promised to prosecute her, despite Comey’s recommendation that Clinton not face charges for her use of a private email server and address while secretary of state. He has continued to criticize Comey since becoming president, most recently in a tweet last week:

FBI Director Comey was the best thing that ever happened to Hillary Clinton in that he gave her a free pass for many bad deeds! The phony... — Donald J. Trump (@realDonaldTrump) May 3, 2017

Yet Rosenstein’s rationale for firing Comey was precisely the opposite: He concluded that the FBI director had badly overstepped his bounds in his handling of the Clinton case.

“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,” Rosenstein wrote in a letter to Attorney General Jeff Sessions.

Rosenstein identified several errors. First, he said Comey “usurp[ed]” the authority of Attorney General Loretta Lynch by announcing that he did not recommend charges against Clinton. Comey made that choice in part because he believed Lynch was compromised by a meeting with Bill Clinton shortly before the decision.

“Compounding the error, the Director ignored another longstanding principle: we do not hold press conferences to release derogatory information about the subject of a declined criminal prosecution,” Rosenstein wrote. In that press conference, Comey accused Clinton and her aides of being “extremely careless” with classified information.

Finally, Rosenstein said that Comey’s October 28, 2016, letter to Congress in which he announced the discovery of new emails related to the Clinton case was an error, and that his defense that not to write Congress would have been “concealing” something was wrong. On November 6, two days before the election, Comey followed up and informed Congress that the FBI had found no new evidence to change its recommendation. Clinton has blamed the October 28 letter for her loss on November 8, and some independent analysts, such as Nate Silver, agree.

Rosenstein wrote that he had conferred with a large group of former attorneys general and deputy attorneys general from both parties, stretching back to the Ford administration, and that nearly all of them shared his judgment that Comey had dangerously eroded traditions.

It is ironic, then, that Trump—a president who has made manifest his disdain for traditions—has fired an FBI director who he didn’t like for breaking tradition in making a decision with which Trump disagreed. But while Trump may owe his presidency to Comey’s interference in the Clinton case, the FBI director had more recently become a thorn in his side. The FBI has been pursuing an investigation into Russian interference in the election, and whether Trump or aides colluded with the Russians. Comey’s disclosure of that investigation, on March 20, was a major blow to Trump, who insists that questions about Russia constitute a “charade.” Comey also debunked the president’s claim, offered without evidence, that President Obama “wiretapped” Trump during the campaign.