David Petraeus & Paula Broadwell
David Petraeus resigns as CIA director. Image: Twitter

The FBI withheld the information that former director of the Central Intelligence Agency (CIA) David Petraeus was having an extramarital affair and was exchanging emails that could have compromised national security until the re-election of President Barack Obama.

The FBI opened the investigation into Petraeus last spring, when he was stationed in Afghanistan. His name turned up in the course of an agency inquiry into a cyber complaint involving two women, one of them Paula Broadwell, with whom he was having an affair.

Broadwell is the author of Petraeus's biography, All In: The Education of David Petraeus. She was given unique access to the CIA director and was embedded with the soldiers for a year in Afghanistan.

The FBI was looking into "an issue with two women and they stumbled across the affair with Petraeus," government security sources told Reuters.

Broadwell was sending threatening emails to another woman who was close to Petraeus, whose relationship with him is yet to be revealed. The woman approached the FBI with cyber harassment claims, and the agency traced the emails to Broadwell.

Considering his access to military secrets and the fact that he was married, the FBI continued to intercept Petraeus's private emails, many of them containing sexually explicit references, one even referring to sex under a desk.

The FBI investigation revealed that Petraeus actively pursued Broadwell even after she broke up with him after his appointment as CIA director on 6 September, 2011. The agency found out that he had sent thousands of emails to Broadwell.

However, the FBI withheld the investigation reports on Petraeus from Director of National Intelligence James Clapper, who oversees the CIA and other intelligence agencies, until election day.

Petraeus announced his resignation three days after the re-election of Barack Obama, acknowledging his extramarital affair.

"After being married for 37 years, I showed extremely poor judgment by engaging in an extramarital affair. Such behaviour is unacceptable, both as a husband and as the leader of an organisation such as ours," said Petraeus.

Petraeus's resignation comes at a time when the CIA is embroiled in controversies such as the Benghazi attack that killed four Americans, including US ambassador to Libya Chris Stevens, and the recent Iranian attack on US drone.

Now the question being asked is why the FBI did not act earlier, even though it had evidence that Petraeus's email accounts were vulnerable to hackers, thereby posing a risk to national security.