The Justice Department will not charge former acting FBI director Andrew McCabe with lying to investigators about a media disclosure, according to people familiar with the matter and McCabe’s legal team, ending a long-running inquiry into a top law enforcement official who authorized the bureau to investigate President Trump and soon became the commander in chief’s political punching bag.

The department revealed the decision to McCabe’s team Friday. The move was said to infuriate Trump, who has raged publicly and privately in recent months that McCabe and others he considers political enemies should be charged with crimes.

The decision could amplify the tension between Trump and his Justice Department, especially Attorney General William P. Barr, who on Thursday publicly rebuked the president for tweeting about Justice Department criminal cases.

President Trump on May 23 suggested former FBI officials James B. Comey, Andrew McCabe, Peter Strzok and Lisa Page committed treason. (The Washington Post)

A White House official said that Trump was not given a heads-up and was upset, and that White House lawyers moved to calm the president. The official, speaking on the condition of anonymity to reveal internal discussions, said Trump “believes very strongly that action should be taken.”

Michael R. Bromwich and David Schertler, McCabe’s attorneys, said in a statement that the D.C. U.S. attorney’s office had called and informed them that the case “has been closed.” The call was followed by a letter from J.P. Cooney, chief of that office’s fraud section, and Molly Gaston, an assistant U.S. attorney, that the lawyers released publicly.

McCabe, a CNN contributor, said on the network that the investigation was a “horrific black cloud that’s been hanging over me and my family for almost the last two years,” and the formal end of it was a “relief” he could not put into words.

“It’s just a very emotional moment for my whole family,” he said.

McCabe authorized the FBI to begin investigating Trump personally for possible obstruction of justice in connection with the probe of whether the Trump campaign coordinated with Russia to influence the 2016 election.

The veteran law enforcement official later became the focus of a grand-jury probe over allegations from the Justice Department inspector general that he lied to investigators exploring a media disclosure. The investigation was led by the D.C. U.S. attorney’s office. A spokesman for that office declined to comment Friday.

What exactly happened in the case remains unclear. Justice Department officials authorized prosecutors to seek an indictment of McCabe last year, and in September a grand jury that had been hearing evidence was summoned back after a months-long hiatus to consider the case. But the day came and went with no public charges being filed. McCabe’s legal team sought to press the Justice Department for a status update but was told nothing.

The case was particularly complicated because of Trump’s public attacks on McCabe, which many viewed as an attempt to politicize the Justice Department and seek the prosecution of someone the president viewed as a political foe.

According to materials made public Friday in a Freedom of Information Act case related to the investigation, a federal judge in D.C. warned prosecutors in the case that the public was watching and that comments from the White House were detrimental.

“I just think it’s a banana republic when we go down that road and we have those type of statements being made that are conceivably, even if not, influencing the ultimate decision,” Judge Reggie Walton said. “I think there are a lot of people on the outside who perceive that there is undue inappropriate pressure being brought to bear.” He added later, “I think as a government and as a society we’re going to pay a price at some point for this.”

McCabe took over as acting chief of the FBI after Trump fired James B. Comey from the post in May 2017. From the start, there was tension between the two men. McCabe has alleged that Trump in one of their early talks called his wife, Jill McCabe, a “loser” because of her failed run for a state Senate seat in Virginia.

Trump denied that. The president, though, has tweeted relentlessly about the former law enforcement official, calling the day he was ousted from the bureau a “great day for Democracy,” alleging Andrew McCabe damaged the FBI’s reputation and suggesting he should be charged with a crime. In a lawsuit over his firing from the bureau — which came after the inspector general alleged he had lied — McCabe asserted he had been ousted illegally as part of a plot by Trump to remove those who were not loyal to him politically.

The media disclosure at issue came in the fall of 2016, a particularly fraught period at the bureau when officials were wrapping up an investigation of Hillary Clinton’s use of a private email server while she was secretary of state and starting to ramp up the Russia case.

McCabe authorized two FBI officials to speak for a Wall Street Journal report detailing tension inside the FBI and Justice Department over the Clinton email case and a separate investigation of the Clinton family foundation. But he initially denied having done so when FBI officials — and, later, the inspector general’s office — tried to determine who might have spoken to the media.

The inspector general accused McCabe of lying at least four times, three of them under oath, and even misleading Comey, his boss at the time.

Spencer S. Hsu contributed to this report.