CIA director David Petraeus's extra-marital affair, which forced him to resign, was uncovered during an investigation into a potential breach of his Gmail account, reports say.
Unnamed officials said the FBI was checking his private account when it found Mr Petraeus was having an affair with his biographer, Paula Broadwell.
Mr Petraeus described his behaviour as "unacceptable" for the leader of the nation's main intelligence agency.
President Barack Obama has praised him.
His resignation came just three days after President Obama's re-election.
The four-star general became CIA boss in 2011 after heading international forces in Iraq and later in Afghanistan.
He was the highest-profile military officer of the post-9/11 years, winning plaudits for his role running the "surge" in Iraq and implementing a counter-insurgency strategy in Afghanistan.
He left his command role in Afghanistan in mid-2011, resigning from the US Army to head the CIA after Leon Panetta became defence secretary.
'Extremely poor judgment'
Shortly after Mr Petraeus resigned, reports emerged that the FBI had uncovered the affair during the course of an investigation into a potential breach involving his emails.
The FBI was monitoring Mr Petraeus's email account to check whether Mrs Broadwell had access to it, administration officials were quoted as saying.
FBI agents then met Mr Petraeus to discuss the investigation.
Announcing his decision to stand down, the former general was full of contrition.
"After being married for over 37 years, I showed extremely poor judgment by engaging in an extra-marital affair," Mr Petraeus said in a statement.
"Such behaviour is unacceptable, both as a husband and as the leader of an organisation such as ours. This afternoon, the president graciously accepted my resignation."
Mrs Broadwell is a Harvard University research associate and PhD candidate at King's College, London.
She has a military background, graduating from the same West Point Academy as Mr Petraeus. She is married to radiographer Scott Broadwell and lives in Charlotte, North Carolina.
She spent months alongside the then-general in Afghanistan while researching her 2011 book, All In: The Education of General David Petraeus. The book was widely seen as a positive account of his leadership methods.
Last week Mrs Broadwell wrote a piece for Newsweek entitled General David Petraeus's Rules for Living.
In his statement, Mr Obama said Mr Petraeus had "provided extraordinary service to the United States for decades", citing both his time as CIA director and as a top general.
"By any measure, through his lifetime of service David Petraeus has made our country safer and stronger."
"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."
Senior Obama adviser David Axelrod said the president had not known about the Petraeus issue during the campaign, and that the former general had come to Mr Obama after the election to offer his resignation.
CIA deputy director Michael Morell will serve as acting director of the agency, the White House confirmed. Eventually Mr Obama must nominate a new director to head the agency, who will then need to be confirmed by the Senate.
Mr Morell, who is well respected at both the White House and on Capitol Hill, also served as acting director following the departure of former CIA chief Leon Panetta.
He is expected to testify before the Senate Intelligence Committee at a hearing scheduled for next week on the deaths of US personnel during an attack on the US consulate in Benghazi, Libya.
The CIA faces a potential period of instability after Mr Petraeus' resignation, as it also deals with a budget squeeze.