Ex-FBI Director James Comey savages President Trump in his bestselling new tell-all, “A Higher Loyalty” — but also skewers former Attorney General Loretta Lynch for her dubious handling of the Hillary Clinton email probe.

Lynch, wrote Comey, had a “tortured half-out, half-in approach” to the investigation, and he said he even considered calling for a special prosecutor to be appointed to oversee the probe because of Lynch’s ambivalence.

“But I decided it would be brutally unfair to do that,” he wrote.

“A world-class FBI team had investigated Hillary Clinton for a year, and all of them — to a person — believed there was no prosecutable case.”

Still, he described Lynch’s behavior regarding the probe as “very strange” in that she rejected calls to recuse herself from the case while not playing much of a role in the investigation.

“She chose a very strange position — that she would not remove herself, but that she would accept my recommendation about the case,” he added.

“In effect, she was removing herself but not removing herself. Again, very strange.”

Comey also wrote that still-classified information could have “cast serious doubt” on Lynch’s ability to investigate Clinton.

He called that info a “development still unknown to the American public to this day” that in part convinced him to take a more active role in the probe.

Comey added that “the unverified material would undoubtedly have been used by political opponents to cast serious doubt on the attorney general’s independence in connection with the Clinton investigation” — but provides no clues to the nature of his tantalizing revelation.

The former top G-man also bristled when Lynch ordered him to call the probe into Clinton’s emails “a matter” rather than “an investigation.”

“Call it ‘a matter,’” Comey quotes Lynch as telling him during a 2016 meeting.

“Why would I do that?” he said he replied.

“Just call it ‘a matter,’” she snapped back.

He said he believed she was parroting the Clinton campaign’s efforts to dismiss the significance of the probe.

“The attorney general seemed to be directing me to align me with the Clinton campaign strategy,” he wrote, adding caustically that “The FBI didn’t do ‘matters.’”

But he followed orders.

Still, his grave concerns about Lynch prompted him to provide the public with an independent opinion about the investigation — a move that led to howls from Trump and the GOP, who accused him of circumventing the chain of command.

“I needed to visibly step away from Loretta Lynch and do something I never could have imagined before 2016: having the FBI separately offer its views to the American people … by making public my recommendation” that Clinton not be charged “and the thinking behind it.”

Americans, he argued, “needed and deserved transparency, and I believed that I had the independent reputation to step out front and take the hits.”

In another passage, he portrayed Lynch as a political actor more concerned with appearances than the truth.

The pair met privately days before the election, and the AG gave him a hug, telling him he had done the right thing when he made his sudden announcement that the feds’ probe into Clinton’s emails was reopening — only to say days later that it was once again closed with no signs of criminality.

“She said, with just the slightest hint of a smile, ‘Try to look beat up.’ She had told somebody she was going to chew me out for what I had done. What a world,” he wrote.

Later, however, he wrote that “I, for one, didn’t see any instance when Attorney General Lynch interfered with the conduct of the investigation” into the former first lady.

He also dismissed the significance of the infamous tarmac meeting between Lynch and Bill Clinton — arguing that if Bubba was intent on influencing the investigation into his wife’s private email server, he wouldn’t have done so in such a public manner “in broad daylight.”

Comey also noted that during the Obama administration, he worked with two attorney generals, Eric Holder and Lynch, and offered his opinions on each.

He described both as “intelligent and personable lawyers” and added, “I liked them both.”

But he also seemed to imply that she might not have been up to the job.

“Lynch was much quieter and new to Washington. She spoke little, and when she did, frequently seemed tightly scripted,” he wrote.

The former top G-man also said that Lynch’s relationship with Deputy Attorney General Sally Yates seemed “distant and strained” and that “their staffs simply didn’t talk to each other.”

Comey, whom Trump called “a slime ball” and “proven LEAKER & LIAR” on Friday in his latest tweetstorm, spilled his guts about the president in an interview with ABC News’ George Stephanopoulos that will air Sunday at 10 p.m.