Former CIA director David Petraeus has entered into an agreement with federal prosecutors to plead guilty to a misdemeanor charge of mishandling classified information the government says he provided to his mistress.

The Department of Justice filed three documents in a US District Court on Tuesday ‒ pertaining to a criminal information, a plea agreement and a statement of facts ‒ the agency said in a statement. The deal covers one count of unauthorized removal and retention of classified material, which carries a maximum penalty of one year in prison, a $100,000 fine or both, as well as up to five years’ probation.

Petraeus was accused of giving Paula Broadwell, his biographer and mistress, high-level classified documents relating to the 2012 attacks on the US consulate in Benghazi, Libya.

The plea agreement will allow the retired four-star general to avoid a trial, where the sordid details of his affair with Broadwell, a former Army Reserve officer, would have become public, according to the New York Times. Petraeus is still married to Holly Petraeus, the assistant director for the Office of Servicemember Affairs at the Consumer Financial Protection Bureau.

Petraeus’ extramarital activities led to his resignation as the director of the CIA three days after President Barack Obama was reelected in 2012. The affair came to light when the FBI began investigating threatening emails mentioning Petraeus that were sent to a third party ‒ later identified as socialite Jill Kelley ‒ by Broadwell.

A probe of Broadwell's emails revealed Petraeus' affair with his biographer, and that she had been given access to the CIA director’s work email account, and highly classified information was found stored on Broadwell’s personal computer.

Broadwell herself revealed she knew more information about Benghazi than was revealed to the American public when she gave a speech at the University of Denver in October 2012 ‒ just over a month after the attack and two weeks before Petraeus resigned.

“Now I don’t know if a lot of you heard this, but the CIA annex had actually had taken a couple of Libya militia members prisoner,” Broadwell told the alumni symposium. “And they think that the attack on the consulate was an effort to try to get these prisoners back. So that’s still being vetted.”

The CIA denied her claims that the CIA was holding anyone prisoner at the Benghazi consulate. Until his guilty plea, Petraeus maintained that he hadn't given Broadwell any classified material. In January, the FBI and Justice Department recommended that felony charges be brought against the former CIA head for compromising US national security.