A former Secret Service officer who published an explosive tell-all from his days guarding the Bill and Hillary Clinton White House is planning to file a defamation lawsuit against his detractors, The Post has learned.

A lawyer for Gary Byrne, whose book “Crisis of Character: A White House Secret Service Officer Discloses His Firsthand Experience with Hillary, Bill, and How They Operate,” has sent notices to Media Matters for America and David Brock informing them that he intends to file suit.

“Officer Byrne will bring legal action against you, in your personal capacity, and against Media Matters,” a lawyer for the former Secret Service officer wrote to Brock, a loyal Clinton ally and the founder of the liberal advocacy group Media Matters.

The letter requests Brock and Media Matters to “hold” all records and communications associated with their communications regarding Byrne — including “Any communication(s) between David Brock and The Honorable Hillary Rodham Clinton” regarding the former Secret Service officer, suggesting there might be collusion between the campaign and her defenders.

It also demands Brock “immediately and publicly retract any statement or inference by yourself and/or Media Matters to the effect that Officer Byrne was not fully truthful in recounting within ‘Crisis of Character’ details from any previous testimony.”

Additionally, Byrne’s attorney demanded a retraction for “the utterly false statement(s) that Officer Byrne was not in close proximity to President William Jefferson Clinton.”

His lawyer states that “some of our best witnesses to such immediacy are George Stephanopoulos, John Podesta, Leon Panetta, Bruce Lindsey, Hillary Rodham Clinton and President Clinton himself — who appear to have already confirmed … under oath … the regular proximity of Officer Byrne to the President for many years.”

Byrne claims the liberal advocacy group tried to hurt his credibility to defend the Clintons.

Lawyers for Brock and Media Matters, Marc Elias and Ezra Reese, acknowledged receiving the letter from Byrne’s lawyer.

Elias is also a lawyer for Hillary Clinton’s presidential election campaign.

Byrne, who has been a surrogate for Donald Trump’s presidential campaign, told The Post, “We’re moving forward with the suit regardless” of whether retractions are issued. My goal here is to get the message out – that everything in my book is true.”

Byrne has sent a similar letter — and has threatened similar legal action — to Jan Gilhooly, president of the Association of Former Agents of the United States Secret Service, who also questioned the claims made in “Crisis of Character.”

Byrne expects the legal filings to come after the November presidential election.