Photo
David H. Petraeus, left, in Denver in September. A plea deal would spare Mr. Petraeus a high-profile trial where embarrassing details about his affair would have been presented to the jury and made public.CreditAaron Ontiveroz/The Denver Post, via Associated Press 
WASHINGTON —  David H. Petraeus, the best-known military commander of his generation, has reached a plea deal with the Justice Department and admitted providing his highly classified journals to a mistress when he was the director of the C.I.A.
Mr. Petraeus has agreed to plead guilty to one count of unauthorized removal and retention of classified material, a misdemeanor. He is eligible for up to one year in prison but prosecutors will recommend a sentence of probation for two years and a $40,000 fine.
The plea deal completes a spectacular fall for Mr. Petraeus, a retired four-star general who was once discussed as a possible candidate for vice president or even president. He led the wars in Iraq and Afghanistan and was the architect of a counterinsurgency strategy that at one time seemed a model for future warfare.
But the deal also ends two years of uncertainty and allows Mr. Petraeus to focus on his lucrative post-government career as a partner in a private equity firm and a worldwide speaker on national security issues. Even while under investigation, he has advised the White House on Iraq and terrorism issues.
The mistress, Paula Broadwell, is a former Army Reserve officer who had an affair with Mr. Petraeus in 2011, when she was interviewing him for a biography, “All In: The Education of General David Petraeus.”
During one of the interviews for that book, Ms. Broadwell asked about his “black books,” the notebooks that contained handwritten classified notes about official meetings, war strategy, intelligence capabilities, and the names of covert officers.
“They are highly classified, some of them,” Mr. Petraeus replied, according to an excerpt from the taped interview included in court documents. Three weeks later, Mr. Petraeus emailed Ms. Broadwell and agreed to share the black books. He gave them to her the next day.
When questioned by the F.B.I., Mr. Petraeus denied providing Ms. Broadwell with classified information. “These statements were false,” federal prosecutors wrote. “Defendant David Howell Petraeus then and there knew that he previously shared the black books with his biographer.” A lawyer for Mr. Petraeus did not respond to a message seeking comment.
Mr. Petraeus resigned as the director of the C.I.A. in 2012, three days after President Obama was re-elected. At the time, Mr. Petraeus acknowledged the affair, but denied any criminal wrongdoing.
The plea deal spares Mr. Petraeus a high-profile trial where embarrassing details about the affair would have been presented to the jury and made public. Mr. Petraeus is still married to Holly Petraeus.
Mr. Petraeus received most of his accolades for his service in Iraq. He was credited with directing the so-called surge of American forces in 2007 that pushed militants of Al Qaeda, who had taken control of several major cities and provinces, out of the country, stabilizing Iraq and allowing the withdrawal of all American forces about five years later.
In 2010, Mr. Obama asked Mr. Petraeus to attempt the same feat in Afghanistan, where the Taliban had gained significant territory. His counterinsurgency measures at that time had some success, but not nearly as much as in Iraq.
Nevertheless, he was revered by members of both parties, and in 2011, Mr. Obama tapped him to lead the C.I.A.
Since leaving the C.I.A., the globe-trotting Mr. Petraeus has carved out a lucrative life for himself as a partner in Kohlberg Kravis Roberts, one of New York’s wealthiest — and most secretive — private equity firms, and also in academia as a paid public speaker. He has taught at some of the nation’s most prestigious universities, including Harvard.
“The broader nation needs his advice, and I think it’s been evidence that people still want to hear from him,” said Michael E. O’Hanlon, a senior fellow with the Brookings Institution. “People are forgiving and know he made a mistake. But he’s also a national hero and a national resource.”
Mr. Petraeus’s friends and allies have been highly critical of the Justice Department for keeping the investigation open so long. Republicans in Congress accused Attorney General Eric H. Holder Jr., of using the investigation to silence Mr. Petraeus. On the other side, some investigators were privately critical of the Justice Department for not moving more aggressively against Mr. Petraeus, particularly when Mr. Holder has led a crackdown on government officials who reveal secrets to journalists.
F.B.I. agents discovered the affair as they investigated cyberstalking allegations that had been made by Jill Kelley, one of Mr. Petraeus’s friends. Ms. Kelley, of Tampa, Fla., told the F.B.I. that an anonymous person had been sending her threatening emails that told her to stay away from Mr. Petraeus.
The agents determined that the emails were coming from Ms. Broadwell. As they investigated Ms. Broadwell, they learned of the affair and found evidence that Mr. Petraeus had shared classified information with her.
Despite the affair and reports that the F.B.I. and Justice Department prosecutors had recommended charges against him, several senators continued to support him.
In a letter to Mr. Holder in December, Senator John McCain, Republican of Arizona, said the investigation had robbed the United States of its most experienced military leader. On Tuesday, Mr. McCain said in a statement that it is time to consider the matter closed.
“At a time of grave security challenges around the world,” Mr. McCain wrote, “I hope that General Petraeus will continue to provide his outstanding service and leadership to our nation, as he has throughout his distinguished career.”
In the days after Mr. Petraeus resigned in 2012, Mr. Obama appeared to clear him of any significant wrongdoing. At Mr. Obama’s first news conference after being re-elected, the president said he had no evidence that Mr. Petraeus had disclosed classified information “that in any way would have had a negative impact on our national security.”
“We are safer because of the work that Dave Petraeus has done,” Mr. Obama said, referring to his career in government. “And my main hope right now is — is that he and his family are able to move on and that this ends up being a single side note on what has otherwise been an extraordinary career.”
But while the disclosures may not have directly affected national security, the F.B.I. found that they amounted to a significant security breach — especially because they had been committed by the C.I.A. director.
While the details were salacious — a love affair that toppled the career of a national icon — Mr. Petraeus is far from the first high-ranking official accused of mishandling classified information. Attorney General Alberto R. Gonzales was admonished but not charged in 2008 for keeping information about the National Security Agency’s wiretapping program at his house.
John M. Deutch, the C.I.A. director from May 1995 to December 1996, lost his security clearances but was not charged for keeping government secrets on his home computer. Samuel R. Berger, a former national security adviser, pleaded guilty in 2005 to a misdemeanor and paid a $50,000 fine for removing classified documents from the National Archives.
But Mr. Petraeus received a light penalty compared to others caught up in Mr. Holder’s crackdown on leaks. Stephen J. Kim, a contractor, received a yearlong prison sentence for disclosing classified information to a reporter for Fox News. A former F.B.I. bomb technician, Donald Sachtleben, received nearly four years in prison for discussing classified information with The Associated Press. And Jeffrey A. Sterling, a former C.I.A. officer, faces the possibility of a lengthy prison term for talking about classified information with a reporter for The New York Times.
Correction: March 3, 2015 
An earlier version of this article misstated the year of the surge of American forces in Iraq. It was 2007, not 2006.