Gen. David Petraeus has resigned as director of the Central Intelligence Agency, MSNBC reports.

MSNBC host Andrea Mitchell broke the news Friday afternoon, reading Petraeus' resignation letter on air.

Petraeus wrote in the letter to the CIA staff on Friday that he had gone to the White House on Thursday and asked the president "for personal reasons" to resign.

"After being married for more than 37 years I showed extremely poor judgment by engaging in an extramarital affair," Petraeus wrote in his letter. "Such behavior is unacceptable, both as a husband and as a leader of an organization such as ours."

Petraeus' wife is Holly Petraeus, whom he met when he was a cadet at the U.S. Military Academy at West Point, the AP reports. Click here for more on Holly Petraeus.

He was reportedly having an affair with Paula Broadwell, the author of his biography.

The retired four-star general led the U.S. military in Iraq and Afghanistan. President Barack Obama appointed him to direct the CIA in September 2011.

Petraeus said that the president accepted his resignation on Thursday.

The full text of Petraeus' resignation letter is below, courtesy of CNN.

According to the New York Times, some senior members of Congress were told about Petraeus' resignation six hours before it was announced. White House officials said they knew he was considering resignation as early as Wednesday night.

The FBI learned of the affair after officials monitored Petraeus' email, officials told the AP. They were investigating claims that Broadwell had access to his email.

The president also released a statement on Petraeus' resignation Friday. "David Petraeus has provided extraordinary service to the United States for decades. By any measure, he was one of the outstanding general officers of his generation, helping our military adapt to new challenges, and leading our men and women in uniform through a remarkable period of service in Iraq and Afghanistan, where he helped our nation put those wars on a path to a responsible end. As Director of the Central Intelligence Agency, he has continued to serve with characteristic intellectual rigor, dedication, and patriotism. By any measure, through his lifetime of service David Petraeus has made our country safer and stronger."

The president said that Michael Morrell, the CIA's deputy director, would serve as acting director.

As for who will replace Petraeus in the longterm, a former senior intelligence official told AOL Defense that Mike Vickers is a leading candidate.

"The prevailing wisdom is that Mike Vickers wants this with all his heart and soul," the official told AOL Defense. Vickers, now the Undersecretary of Defense for Intelligence, is the legendary former CIA operative who led the war against the Soviets in Afghanistan chronicled in the book, Charlie Wilson's War. Another candidate is Stephanie O'Sullivan, the principal Deputy Director of National Intelligence.

Petraeus's resignation came at a time when his office was under extraordinary pressure over its role in the attack in Benghazi, Libya, when four Americans, including the U.S. ambassador, were killed.

For many weeks the White House had come under intense pressure for the attack, before it finally emerged that the CIA had actually played a central role in the episode. Two of the Americans killed were identified as undercover agents for the CIA, and the vast majority of Americans on the ground that night turned out to be with the agency.

In a Wall Street Journal article a week before the election, several administration officials pointed to Petraeus specifically and accused him of mishandling the controversy, by appearing to be aloof and delivering misinformation to the White House in the early days after that attacks.

Congress intends to continue to investigate the incident, and Petraeus was expected to testify during a closed-door hearing next week before the Senate Intelligence Committee.

Sen. Dianne Feinstein (D-Calif.), the head of the Senate Intelligence Committee, released a statement responding to Petraeus' resignation. "I wish President Obama had not accepted this resignation," Feinstein said, "but I understand and respect the decision."

Speaking on CNN, former CIA operative Bob Baer noted that while resignations from extramarital affairs are not unheard of at the agency, they are almost never the announced reason for giving up the post.

"I think there's a big story behind it," Baer said.

Full text of Petraeus' resignation letter:

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. 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.

As I depart Langley, I want you to know that it has been the greatest of privileges to have served with you, the officers of our Nation’s Silent Service, a work force that is truly exceptional in every regard. Indeed, you did extraordinary work on a host of critical missions during my time as director, and I am deeply grateful to you for that.

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.

Thank you for your extraordinary service to our country, and best wishes for continued success in the important endeavors that lie ahead for our country and our Agency.

With admiration and appreciation,

David H. Petraeus

Joshua Hersh contributed reporting.

Watch BuzzFeed reporter Michael Hastings, who has covered Petraeus for years, discuss the affair on HuffPost Live below.

Loading Slideshow...
  • Super Bowl XLIII Football

  • CIA-Director David Petraeus

  • Gen. Petraeus Testifies At Senate Confirmation Hearing

    WASHINGTON - JUNE 29: U.S. Gen. David Petraeus, the commander of U.S. forces in the Middle East, speaks during his confirmation hearing before the Senate Armed Services Committee as his wife Holly Petraeus listens on Capitol Hill June 29, 2010 in Washington, DC. Petraeus has been appointed by U.S. President Barack Obama to replace U.S. Gen. Stanley McCrystal as commander of the United States Forces Afghanistan. (Photo by Brendan Smialowski/Getty Images)

  • Defense Secretary Panetta Holds Briefing At Pentagon

    ARLINGTON, VA - OCTOBER 18: Holly Petraeus (R), assistant director for the Office of Servicemember Affairs at the Consumer Financial Protection Bureau, speaks as Acting Deputy Assistant Secretary of Defense for Military Community and Family Policy Chuck Milam looks on during a news briefing October 18, 2012 at the Pentagon in Arlington, Virginia. The Pentagon held a briefing on efforts to enhance the financial health of the force. (Photo by Alex Wong/Getty Images)

  • Petraeus Retirement

  • Petraeus Intelligence

  • Fort Cambell General Returns

  • CIA Director David Petraeus Rings The Opening Bell At The New York Stock Exchange

    NEW YORK, NY - SEPTEMBER 18: Central Intelligence Agency Director David Petraeus walks the floor of the New York Stock Exchange to ring the Opening Bell as the CIA Commemorates it's 65th Anniversary on September 18, 2012 in New York City. Stocks fell in early trading as investors continued to be concerned about Europe and the global economy. (Photo by Spencer Platt/Getty Images)

  • Biden Petraeus CIA

  • CIA-Direktor David Petraeus zurueckgetreten

  • CIA Director David Petraeus, testifies b

    CIA Director David Petraeus, testifies before the US Senate Intelligence Committee during a full committee hearing on 'World Wide Threats.' on January 31, 2012 on Capitol Hill in Washington, DC. Witnesses include: Director of National Intelligence, James Clapper, FBI Director Robert Mueller(L); Defense Intelligence Agency Director Lt. Gen. Ronald Burgess; National Counter terrorism Center Director Matthew Olsen; Assistant Secretary of State for Intelligence and Research Philip Goldberg; and Homeland Security Undersecretary for Intelligence and Analysis Caryn Wagner. AFP PHOTO/Karen BLEIER (Photo credit should read KAREN BLEIER/AFP/Getty Images)

  • Military Family Spending

  • Defense Secretary Panetta Holds Briefing At Pentagon

    ARLINGTON, VA - OCTOBER 18: Acting Deputy Assistant Secretary of Defense for Military Community and Family Policy Chuck Milam (R) speaks as Holly Petraeus, assistant director for the Office of Servicemember Affairs at the Consumer Financial Protection Bureau, looks on during a news briefing October 18, 2012 at the Pentagon in Arlington, Virginia. The Pentagon held a briefing on efforts to enhance the financial health of the force. (Photo by Alex Wong/Getty Images)

  • Biden Petraeus CIA

  • House Holds Hearing On Protecting Service Members In Consumer Financial Marketplace

    WASHINGTON, DC - NOVEMBER 03: Holly Petraeus, assistant director for service member affairs at the Consumer Financial Protection Bureau, participates in a Senate Banking, Housing and Urban Affairs Committee hearing on Capitol Hill, on November 3, 2011 in Washington, DC. The committee heard testimony from Petraeus on protecting veterans and active service members and their families in the consumer financial marketplace. (Photo by Mark Wilson/Getty Images)

  • House Holds Hearing On Protecting Service Members In Consumer Financial Marketplace

    WASHINGTON, DC - NOVEMBER 03: (L-R) Sen. Jack Reed (D-RI) introduces himself to Holly Petraeus, assistant director for service member affairs at the Consumer Financial Protection Bureau, during a Senate Banking, Housing and Urban Affairs Committee hearing on Capitol Hill, on November 3, 2011 in Washington, DC. The committee heard testimony from Petraeus on protecting veterans and active service members and their families in the consumer financial marketplace. (Photo by Mark Wilson/Getty Images)

  • Petraeus Retirement

  • David Petraeus Sworn In As CIA Director

    WASHINGTON, DC - SEPTEMBER 06: Vice President Joseph Biden (R) swears in David Petraeus (C) to be Director of the Central Intelligence Agency, while his wife Holly Petraeus holds a Bible, in the Roosevelt Room at the White House, on September 6, 2011 in Washington, DC. General Petraeus retired from the U.S. Army last week, and has now become the 20th director of the CIA. (Photo by Mark Wilson/Getty Images)