According to his letter of resignation, Petraeus asked President Barack Obama on Thursday to allow him to resign and on Friday the president accepted.
Petraeus said in a statement that he had shown "extremely poor judgment" in having the affair.
Petraeus has been married for 37 years to Holly Petraeus, whom he met when he was a cadet at the U.S. Military Academy at West Point.
The retired four-star general led the military campaigns in Iraq and Afghanistan, then took the helm of the CIA in September 2011.
(Copyright 2012 The Associated Press. All rights reserved.)