David H. Petraeus, a retired general considered one of the greatest military minds of his generation, pleaded guilty Thursday to a misdemeanor charge of mishandling classified materials, ending a long-running legal saga that had threatened to send him to prison.

Petraeus, who admitted he provided the materials to his former mistress and biographer, will instead face a two-year probationary period. U.S. Magistrate Judge David Keesler also imposed a $100,000 fine — more than double the amount recommended by prosecutors — to reflect the “seriousness of the offense.”

Before the sentencing, Keesler asked Petraeus whether he wanted to address the court. The former CIA director apologized to “those closest to me and others, including this court, for the pain my actions have caused.”

The plea follows a high-profile investigation and prosecution that triggered Petraeus’s resignation from the CIA in 2012. As part of an agreement with prosecutors, he admitted that he improperly removed and retained highly sensitive information in eight personal notebooks that he gave the biographer, Paula Broadwell, to read.

The deal angered FBI agents who worked on the lengthy investigation and who thought Petraeus should have been treated more harshly because of the information in the notebooks and what they considered his lack of candor.

When FBI agents confronted him in his CIA office in October 2012, Petraeus said he had never provided classified information to Broadwell, prosecutors said.

Making a false statement to a federal law enforcement agent during an investigation is a felony, a crime punishable by up to five years in prison. On Thursday, ­Keesler told Petraeus that he had been “untruthful” and that his behavior “constituted a serious lapse of judgment.”

It’s unclear whether the guilty plea will affect the former CIA director’s security clearances or his access to the White House, where he has counseled senior administration officials on how to combat the Islamic State.

The FBI began investigating Petraeus after Broadwell sent threatening e-mails to Jill Kelley, a Florida woman who knew the general from his days in Tampa. Kelley, unaware of the sender’s identity, called the FBI. The bureau later traced the messages to Broadwell and uncovered explicit e-mails between her and Petraeus.

Agents also learned that Broadwell was in possession of classified documents, triggering an investigation of how she obtained them.

The FBI searched Petraeus’s house in April 2013 and found the books in an unlocked drawer in his study. The books contained top-secret information that the Justice Department said could cause “exceptionally grave damage” to national security if disclosed.

That information included code words for secret intelligence programs, identities of covert officers, war strategy and deliberative discussions with the National Security Council.

Although Petraeus provided Broadwell books to help her write the general’s memoir, prosecutors said her book, “All In,” did not contain classified information.

During the Thursday hearing, one of Petraeus’s attorneys, David E. Kendall, told the judge, “This is not a case about dissemination of classified information into the public.” He urged the judge not to incarcerate his client on the misdemeanor charge, which carried a possible sentence of up to one year in prison.

“A sentence of incarceration on these facts would be unprecedented and a deviation from the norm,” said Kendall, who stressed the former general’s service as a commander of two wars.

He also read letters of support for the general and said the proposed sentence in the plea agreement was a “just resolution.”

Keesler accepted the probationary period of two years but said a fine of $40,000 would be insufficient.

“The court simply has a different view,” the judge said.

It’s unclear whether Broadwell will be charged. Any prosecution, current and former officials said, could prove difficult given that Petraeus faces only a misdemeanor. Her attorney declined to comment.

Petraeus now serves as chairman of the KKR Global Institute, a part of the private-equity firm Kohlberg Kravis Roberts.

He is not the first former CIA director to face criminal charges. In December 1996, Director John Deutch resigned after it was discovered that he had stored highly classified documents on his home computer, which was connected to the Internet.

After a criminal investigation, Deutch agreed to plead guilty to a misdemeanor and pay a $5,000 fine. But before the prosecutors could file the papers in federal court, President Bill Clinton pardoned him on his last day in office.

Read more:

Five thoughts Petraeus has about the future of the Middle East

Petraeus: The Islamic State isn’t our biggest problem in Iraq

Today's coverage from Post correspondents around the world