Former CIA Director David Petraeus, whose career was destroyed by an extramarital affair with his biographer, was sentenced Thursday to two years of probation plus a $100,000 fine for giving her classified material while she was working on the book.

Petraeus appeared at the sentencing, which came two months after he agreed to plead guilty to a federal misdemeanor count of unauthorized removal and retention of classified material.

The plea agreement carried a possible sentence of up to a year in prison. In court papers, prosecutors recommended two years of probation and a $40,000 fine. But Judge David Kessler increased the fine to "reflect seriousness of the offense."

In court, before being sentenced, Petraeus apologized "for the pain my actions have caused."

The agreement was filed in federal court in Charlotte, the city where Paula Broadwell, the general's biographer and former lover, lives with her husband and children.

The prospect of probation for Petraeus had been raised as an issue in an unrelated case by supporters of Jeffrey Sterling, a former CIA officer convicted of giving a New York Times reporter classified details of an operation to derail Iran's nuclear ambitions.

Federal prosecutors in Virginia have urged a stiff sentence for Sterling, and probation officers have calculated a sentencing guidelines range of 20 to 24 years.

Supporters including Nobel Peace Prize laureate Archbishop Desmond Tutu argued that Sterling's expected sentence would be out of line with the deal that Petraeus secured.

The affair ruined the reputation of the retired four-star Army general who led U.S. forces in Iraq and Afghanistan.

As part of his deal, Petraeus agreed not to contest the set of facts laid out by the government.

Prosecutors said that while Broadwell was writing her book in 2011, Petraeus gave her eight binders of classified material he had improperly kept from his time as the top military commander in Afghanistan. Days later, he took the binders back to his house.

Among the secret information contained in the "black books" were the names of covert operatives, the coalition war strategy and notes about Petraeus' discussions with President Obama and the National Security Council, prosecutors said.

Those binders were later seized by the FBI in an April 2013 search of Petraeus' Arlington, Virginia, home, where he had kept them in the unlocked drawer of a desk in a ground-floor study.

Prosecutors said that after resigning from the CIA in November 2012, Petraeus had signed a form falsely attesting he had no classified material. He also lied to FBI agents by denying he supplied the information to Broadwell, according to court documents.

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

Broadwell's admiring biography of him, "All In: The Education of David Petraeus," came out in 2012, before the affair was exposed.

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

With a Ph.D. and 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.

Petraeus' command coincided with the "surge" of American forces in Iraq and a plan to pay Sunni militias to fight al-Qaida in Iraq.

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