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.