Updated

General David Petraeus has pleaded guilty to a misdemeanor charge in connection to his handling of classified material -- striking a plea deal with the government that avoids an embarrassing trial and that will likely keep him out of prison over whether he leaked private information to his mistress when he headed up the CIA.

Federal prosecutors will ask the judge for two years of probation for Petraeus.

The criminal complaint, filed Tuesday in the United States District Court for the Western District of North Carolina’s Charlotte Division, charges Petraeus with one count of unauthorized removal and retention of classified material.

The plea deal marks a spectacular fall for the retired four-star general, who was once considered a possible presidential or vice presidential candidate  for the United States.

Petraeus’ mistress, Paula Broadwell, is a former Army  Reserve officer who had an affair with  Petraeus in 2011, when she interviewed him for a biography she was writing on him titled, “All In: The Education of General David Petraeus.”

Petraeus resigned from his post at the head of the CIA in 2012.

Under the plea agreement, prosecutors recommended two years of probation and no prison time. But the judge who hears the plea is not bound by that recommendation. No immediate date was set for Petraeus to enter the plea.

Prosecutors said that while Broadwell was writing her book, Petraeus gave her binders of classified material containing, among other information, his daily schedule and notes about his discussions with President Obama.

Those binders, known was "black books," were seized by the FBI in a search of Petraeus' home. Petraeus lied to FBI agents about providing them to Broadwell and said he never gave her classified material, according to court documents.

Petraeus' lawyers, David Kendall and Robert Barnett in Washington, declined to comment. Her lawyer, Robert Muse of Washington, said he had no comment.

Petraeus admitted having an affair with Broadwell when he resigned as CIA director in November 2012. Both have publicly apologized and said their romantic relationship began only after he had retired from the military.

The former general retained the black books in his home even after he left the Defense Department. In 2011, he delivered them to a home in Washington where Broadwell was staying, according to court papers.

Petraeus left the books with her so she could use them as source material for the biography on him that she published in 2012, prosecutors said. Days later, Petraeus brought the books back to his home in Arlington, Virginia.

He held the CIA post less than a year, not long enough to make a significant mark on the spy agency. The core of his identity has been a military man.

A Ph.D. with a reputation as a thoughtful strategist, Petraeus was brought in by President George W. Bush to command multinational forces in Iraq in 2007, a period when the war began to turn in favor of the U.S., though recent events have proven how ephemeral that was. Petraeus' command coincided with the "surge" of American forces in Iraq and a plan to pay Sunni militias to fight Al Qaeda in Iraq.

With American help, the Sunni tribes were able to push out insurgents and create enough stability for American troops to withdraw in 2011. Those same Sunni areas are now controlled by the Islamic State group, which evolved from the remnants of Al Qaeda after Iraqi's Shiite-led government proved weak.

Petraeus was promoted to commander of U.S. Central Command, which has authority over the Middle East. When Gen. Stanley McCrystal was fired in 2010 by Obama as commander in Afghanistan after his staff made impolitic remarks to a Rolling Stone reporter, Petraeus was brought in to replace him.

He wrote the Army manual on counterinsurgency, a doctrine he embraced throughout his career but which has fallen out of favor in recent years amid the setbacks in Iraq and Afghanistan.

The Associated Press contributed to this report.