Petraeus disclosed the affair in a memo to CIA staff on Friday afternoon, telling them "such behaviour is unacceptable, both as a husband and as the leader of an organization such as ours."
The dispatch came a day after he reportedly told President Barack Obama of the transgression and offered his resignation. Earlier Friday, the president accepted the offer.
Petraeus, one of America's most revered military leaders, had been head of the CIA for barely a year after serving as the commander of international forces in Afghanistan from 2010 to 2011.
Prior to that, he was head of the U.S. Central Command and commanding general of American forces in Iraq.
At the CIA, he replaced Leon Panetta, who moved to the Pentagon to become secretary of defence.
Petraeus, 59, was a highly respected figure in the U.S. capital, and an occasional presence on the city's social scene.
Just last month, the retired four-star general rubbed elbows at the Canadian embassy with Ben Affleck, Jennifer Garner and John Goodman at a reception for the release of Affleck's film, "Argo."
The critically acclaimed movie tells the story of how Canadian and American officials — in particular a daring CIA agent — schemed to help six diplomats escape Iran during the 1979 hostage crisis.
Ambassador Gary Doer, the host of the soiree, later said Petraeus was "the biggest star in the room."
Petraeus has been married for 37 years. His wife, Holly, also works in the Obama administration as an official with the Consumer Financial Protection Bureau.
His resignation marks a stunningly ignominious end to a storied career, made even more sordid by revelations that the FBI is investigating his biographer for improperly trying to access his email and possibly gaining access to classified information.
Paula Broadwell, the author of Petraeus's biography, "All In," is reportedly the focus of the FBI probe.
She was granted exclusive access to Petraeus in Afghanistan and has been interviewed several times, including on "The Daily Show," about the former CIA head. The biography on her now-defunct website stated she is married to a radiologist in Charlotte, N.C., and has two children.
In a written statement, Obama praised Petraeus for providing "extraordinary service" to his country for decades.
"By any measure, through his lifetime of service David Petraeus has made our country safer and stronger," he said.
"Going forward, my thoughts and prayers are with Dave and Holly Petraeus, who has done so much to help military families through her own work. I wish them the very best at this difficult time."
Michael Morell, the agency's deputy director, has been appointed to serve as acting director.
A Canadian intelligence official said the CIA is typically uneasy when those with a military background take control.
"The military is top down, yes-sir-no-sir, and the agency isn't," said the Canadian, who spoke on condition of anonymity.
"They were certainly worried about Petraeus. When Petraeus was commander in Afghanistan, he kept making rosy assertions that the surge was going great and accusing the agency of being too negative. The analysts were worried that he might try to suppress contrary views."
Intelligence officials also worried that Petraeus was too showy, the Canadian said.
"He had a reputation for being talented, hard-working and disciplined, but also a bit a of a showboat. His nickname in the Pentagon was 'King David.'"
Also on HuffPost