The resignation of David H. Petraeus as CIA director followed an FBI investigation of many months, raising the question of why he was not forced out until after the election.In his letter of resignation, Petraeus cited an extra-marital affair he had been having. “After being married for over 37 years, I showed extremely poor judgment by engaging in an extramarital affair,” Petraeus said in his letter to President Obama. “Such behavior is unacceptable, both as a husband and as the leader of an organization such as ours.”Petraeus, who had a distinguished military career, revealed no additional details. However, an FBI source says the investigation began when American intelligence mistook an email Petraeus had sent to his girlfriend as a reference to corruption. Petraeus was commander of U.S. Forces in Afghanistan from July 4, 2010 until July 18, 2011.The investigation began last spring, but the FBI then pored over his emails when he was stationed in Afghanistan.The woman who was having an affair with Petraeus is a journalist who had been writing about him.Given his top secret clearance and the fact that Petraeus is married, the FBI continued to investigate and intercept Petraeus’ email exchanges with the woman. The emails include sexually explicit references to such items as sex under a desk.Such a relationship is a breach of top secret security requirements and could have compromised Petraeus.At some point after Petraeus was sworn in as CIA director on Sept. 6, 2011, the woman broke up with him. However, Petraeus continued to pursue her, sending her thousands of emails over the last several months, raising even more questions about his judgment.Neither Petraeus nor the CIA’s Office of Public Affairs had any immediate comment.FBI agents on the case expected that Petraeus would be asked to resign immediately rather than risk the possibility that he could be blackmailed to give intelligence secrets to foreign intelligence agencies or criminals. In addition, his pursuit of the woman could have distracted him as the CIA was giving Congress reports on the attack on the Benghazi consulate on Sept. 11.The CIA ‘s reporting to Congress included a claim that protests over a YouTube video played a role in the attacks, thus allowing Obama to initially discount the possibility that the U.S. had suffered another terrorist attack just before the election.In contrast, based on real time video and reports, the State Department was reporting that the attack that led to the deaths of four Americans, including U.S. Ambassador J. Christopher Stevens, was terrorist-related. The State Department reported that there were no protests at the consulate.Still, the White House, with concurrence by the FBI and Justice Department, held off on asking for Petraeus’ resignation until after the election. His resignation occurred three days after the election, avoiding the possibility that Obama’s ill-fated appointment of Petraeus could become an issue in the election.FBI agents on the case were aware that such a decision had been made to hold off on forcing him out until after the election and were outraged.“The decision was made to delay the resignation apparently to avoid potential embarrassment to the president before the election,” an FBI source says. “To leave him in such a sensitive position where he was vulnerable to potential blackmail for months compromised our security and is inexcusable.”Michael Kortan, the FBI’s assistant director for public affairs, said he had no comment.