Former U.S. Attorney Preet Bharara has sharply criticized former FBI Director James Comey for speaking “disparagingly and at length” about then-candidate Hillary Clinton in his notorious 2016 press conference announcing she would not be prosecuted.

Comey, who was later fired by President Trump, failed in his duty “to keep your mouth shut,” Bharara writes in his forthcoming memoir "Doing Justice: A Prosecutor’s Thoughts on Crime, Punishment, and the Rule of Law."

The book, due to be published next month and a copy of which was obtained by the Washington Examiner, contains a chapter on the dilemma prosecutors face when they do not have enough evidence to charge a suspect. They must, in such cases, “walk away,” Bharara writes.

Bharara was appointed by President Barack Obama to be U.S. a ttorney for the Southern District of New York in 2009. Trump fired him two months after he was inaugurated in 2017.

“We could demand that our prosecutors explain at length their decisions to walk away, especially when the smell of smoke is strong in public nostrils, so the public can be satisfied in the rectitude of those decisions,” he wrote.

“The prosecutors can get into deep trouble, too, if they talk too much about a decision not to prosecute. That's precisely what got the former FBI director James Comey — who spoke disparagingly and at length about Hillary Clinton even while asserting no criminal case was warranted — rebuked by the inspector general, criticized by everyone, and, depending on whom you believe, fired from his post,” Bharara continued. “When you make the decision to decline — and we declined on significant people, including the mayor of the city of New York and the governor of New York — it becomes difficult to explain fully and transparently to the public why you didn't make a particular decision. After all, the subject has a right to fairness also, to be free from prosecutorial slander. You owe it to the system and to the guidelines of the department, as well as to the presumed innocent party you chose not to charge, to keep your mouth shut.”

Comey held Bharara’s former position as U.S. attorney for the Southern District of New York for nearly two years starting in January 2002. He was fired from the FBI in May 2017 by Trump, who at first cited Comey’s handling of the Clinton email investigation, but then confirmed in an interview with NBC News that the “Russia thing” was on his mind at the time.

Days later, Bharara tweeted that he was “troubled by the timing and reasoning” of the Comey firing.

Yet in the book, he agreed with the widespread criticism of Comey’s news conference dur ing the 2016 presidential campaign, where he announced Clinton would not be referred for prosecution for her handling of classified emails as secretary of state, while calling her actions “extremely careless.”

“As we saw in the deviation from that practice in the Clinton email investigation, trying to justify your action — or lack of action — can lead down a very bad path,” Bharara wrote. “If you're making comments about a case in one instance, like Hillary's emails, you will be asked why you didn't talk publicly about another case, like the Russia case.”

Bharara warned that special counsel Robert Mueller will face that same pressure if he declines to charge Trump.

"If Robert Mueller and others decide not to charge or decline to make a referral on President Trump, it will be very difficult to show the purity of that decision," Bharara wrote. "It's much harder to assess the quality of the decision not to do something than to do something. That is the nature of logic, the difficulty of proving a negative."

While recognizing that “good-faith critics” can ask legitimate questions about prosecutors’ decisions, Bharara called “lock her up” and “lock him up” chants “imbecilic.”

Bharara was also self-reflective in the book, saying he should have tempered a 2015 speech at New York Law School in which he ranted about political corruption in the state of New York, the day after his office announced federal corruption charges against New York State Assembly Speaker Sheldon Silver, a Democrat.

“I might have thought better of the timing of my rant,” he said. “I might have stuck to my pre-planned speech rather than inflamed passions the day after the bombshell charges. I might have shown a little less exuberance. Reading these lines now, more than three years later, I can see how it sounds like something bordering on a political speech, a call to arms. That was not my intention.”

“I was speaking out of earnest frustration about the political cesspool, and I was channeling the frustration of every New Yorker,” he continued. “But are prosecutors allowed to be frustrated, allowed to vent their frustration? Something about the speech felt satisfying, felt good. That should have been the warning sign: if it feels good, it's probably a bad idea.”

"Doing Justice" is scheduled to be published March 19 by Knopf.