CIA Director David Petraeus has resigned because of an extramarital affair.

Petraeus announced the decision in a letter to President Obama released Friday after telling the president the news on Thursday.

“Yesterday afternoon, I went to the White House and asked the president to be allowed, for personal reasons, to resign from my position as D/CIA,” he wrote.

“After being married for over 37 years, I showed extremely poor judgment by engaging in an extramarital affair. 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 wrote.

Petraeus’s wife, Holly, works at the Consumer Financial Protection Bureau set up by the Wall Street reform bill.