Former FBI Director James Comey — in a seemingly transparent effort to rehab his battered image — claims in his new tell-all that President Barack Obama and other top Democrats absolved him of any blame after Hillary Clinton’s shocking election loss.

In “A Higher Loyalty,” Comey says he came into a post-election Oval Office sit-down with Obama with a bad case of the jitters.

“I knew how badly Obama had wanted Hillary Clinton to win the White House. I know he took the loss hard. But I respected President Obama and was very open to whatever it was he had to say,” Comey writes.

He was sure Obama would chastise him for reopening the probe into Clinton’s emails days before the election — only to close

it days later — a development that many blamed for her loss to Donald Trump.

But instead of a tongue-lashing, Obama delivered words of praise.

“I picked you to be FBI director because of your integrity and your ability,” the president said, according to Comey. “I want you to know that nothing — nothing — has happened in the last year to change my view.”

Comey was overcome with emotion.

“Boy, were those words I needed to hear,” he writes.

“I felt a wave of emotion, almost to the verge of tears.”

The scene is one of several vignettes included in the upcoming memoir that describe his sorrowful interactions with Democrats after Clinton’s crushing loss.

Comey also wrote that in a post-election briefing for senators, then-Sen. Al Franken (D-Minn.) confronted him about “the elephant in the room,” which was “what you did to Hillary Clinton.”

He said he asked Senate Majority Leader Mitch McConnell (R-Ala.) if he could reply and was told to “take all the time you need.”

Comey says he then tried to explain the thinking behind his decision to reopen the Clinton probe after her emails were found on a computer shared by her top aide, Huma Abedin, and Abedin’s husband, the disgraced former Rep. Anthony Weiner.

Afterward, a teary-eyed Senate Minority Leader Chuck Schumer grabbed him by the hand and patted him on the chest.

“I know you. You were in an impossible position,” Schumer told him, according to Comey.