CIA Director David Petraeus resigned his post effective immediately in a letter given to President Barack Obama on Friday, citing an unspecified extramarital affair.

"After being married for over 37 years, I showed extremely poor judgement by engaging in an extramarital affair," he wrote in a CIA memo obtained by NBC News. "Such behavior is unacceptable, both as a husband and as the leader of an organization such as ours. This afternoon, the president graciously accepted my resignation."

He added: "Teddy Roosevelt once observed that life's greatest gift is the opportunity to work hard at work worth doing. I will always treasure my opportunity to have done that with you and I will always regret the circumstances that brought that work with you to an end."

His wife, Holly Petraeus, also works for the administration in the Consumer Financial Protection Bureau.

Petraeus is largely credited as the architect of the military's counterinsurgency strategy in Iraq and also oversaw operations in Afghanistan. He took over the CIA in September 2011, after Obama nominated him in April.

"Today, I accepted his resignation as Director of the Central Intelligence Agency," President Obama said in a prepared statement. "I am completely confident that the CIA will continue to thrive and carry out its essential mission, and I have the utmost confidence in Acting Director Michael Morell and the men and women of the CIA who work every day to keep our nation safe. 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."

There were rumors last summer that Petraeus was being courted as a potential running mate for Mitt Romney, but the White House dismissed reports that the president was concerned. Petraeus has said repeatedly that he has no interest in politics.

This video is from MSNBC, aired Friday, November 9, 2012.

Visit for breaking news, world news, and news about the economy