One of the Clintons’ oldest and most trusted legal advisers has urged Hillary to hire a criminal defense attorney to represent her in case she’s indicted for mishandling classified documents on her private email server and for lying under oath.

The adviser, who has been a Clinton confidant for more than 30 years, laid out his concerns about Hillary’s legal exposure in a wide-ranging interview.

“This email thing is spiraling out of control,” he said. “To paraphrase John Dean of Watergate fame, it’s a cancer on her candidacy.

“Frankly,” he continued, “I am used to my advice on legal matters being taken very seriously and acted upon by the Clintons. I’ve told them repeatedly that this FBI email investigation could go in a very dangerous direction very quickly.

“I think Bill takes the matter seriously. But Hillary is still acting as though it’s a political smear job by right-wing zealots.”

In separate phone conversations with Bill and Hillary, the adviser said he warned them that Justice Department prosecutors handling Hillary’s case expect the FBI probe to wrap up much sooner than expected — maybe as soon as the end of this year.

His advice to Hillary: Lawyer up now before it’s too late.“Hillary needs to secure the services of an expert legal counsel — preferably a big-league defense attorney from the Republican side of the aisle,” the adviser said. “She needs someone to find out whether the FBI and Justice Department are likely to conclude that she’s violated federal laws governing national security.”

The Clinton confidant said that his advice has met a lot of resistance among members of Hillary’s campaign staff. But Hillary has been the biggest problem. He described her as being in a state of denial.

He said he was “tearing my hair out” over Hillary’s defiance of his advice, her insistence that the email controversy was all about politics, and her tendency to joke about the whole thing.

“By joking about her email problem and treating it like a p.r. issue, she’s only hurting herself, maybe mortally, with the prosecutors,” the adviser said. “Insulting career FBI and Justice Department investigators is a very bad and ill-advised strategy.

“You don’t want to be blindsided,” he continued. “And if you ignore it, pretend it is a partisan ploy, and act scornfully, it will blindside you.”

During one of his conversations with the Clintons, the discussion turned to the fate of former CIA Director David Petraeus, who avoided criminal charges for mishandling classified material by pleading guilty to a misdemeanor.

“Petraeus wasn’t running for president when he cut a deal with the prosecutors,” she said. “If I admit any kind of guilt — even to a minor wrongdoing — it will sink my chances of winning the nomination.”

But the adviser argued that she had to take that chance.

“Hopefully, the FBI will determine Hillary’s behavior does not amount to a criminal matter, and that she hasn’t violated the letter of the law with security breaches,” he said. “I hope that will be the outcome.

“But from what I know of the case, Hillary is extremely vulnerable. There is going to be blood in the water. The investigators are looking for weak links to get to the bottom of what went on with Hillary’s national security emails. And I’m afraid they will find it.”

Edward Klein’s new book is “Unlikeable: The Problem with Hillary” (Regnery Publishing ), out now. Visit edwardklein.com.