"Yesterday afternoon, I went to the White House and asked the President to be allowed, for personal reasons, to resign from my position," Petraeus said in a letter to CIA colleagues. "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," Petraeus said in the letter.

Officials told The Associated Press that information about the affair surfaced over the course of an FBI probe. Meanwhile, law enforcement sources told NBC News that the FBI is currently investigating Petraeus' biographer, who had extensive access to the general, for improperly trying to access his email and possibly gaining access to classified information. The sources emphasized that Petraeus was not under investigation and added that they did not believe the investigation into author Paula Broadwell would result in criminal charges.

"In his mind, in his views, with his code of ethics and morals, he did a very dishonorable thing," a U.S. military official and long-time aide to Petraeus told NBC News. "This had nothing to do with Benghazi, nothing to do with his relationship with the White House," the official added in reference to the recent questions and criticism leveled at the general for his agency's response to the recent attacks on the U.S. Consulate in Libya.

Mike Morrell, the deputy CIA director and a long time CIA officer, will likely be offered Petraeus' job as acting director, multiple sources told NBC News. Morrell is a longtime CIA analyst, who was traveling with President George W. Bush as his briefer when terrorists struck on Sept. 11, 2001, and was later in the Situation Room with President Obama during the mission that killed Osama bin Laden, NBC News reported.

Obama said in a statement that Petraeus "has provided extraordinary service to the United States for decades" and that his "thoughts and prayers" were with Petraeus and his wife Holly.

"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," Obama said. "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."

In his statement, Obama said that he was confident the CIA would "continue to thrive" and that he had 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," Obama said.

Military justice considers extramarital affairs—ripe ground for blackmailing—to be security threats and possible grounds for court martial, The AP reported.

Sen. Dianne Feinstein, chair of the Senate Intelligence Committee, told NBC News that she would have "stood up for him."

"I wanted him to continue," she said. "He was good, he loved the work, and he had a command of intelligence issues second to none." Feinstein added that Petraeus will no longer be required to testify at hearings next week related to the attack on the U.S. Consulate in Libya Sept. 11.

Petraeus, a West Point graduate who climbed the ranks of the U.S. military, became one of the country’s most high-profile leaders as the top U.S. Commander first in Iraq then in Afghanistan.

He met his wife Holly while a West Point cadet, The AP reported. They are parents to two grown children, a son and a daughter, and live in Virginia, according to the CIA's website.

In January 2011, the Treasury Department named Holly Petraeus to establish the Office of Servicemember Affairs for the Consumer Financial Protection Bureau.

A popular figure in Washington and a media darling, David Petraeus took over as head of the CIA in September 2011 when Leon Panetta took the helm of the Department of Defense. Petraeus kept a much lower profile after transitioning to his new post. His popularity waned as a number of intelligence leaks drew the criticism of Republicans, who accused the CIA and the Obama administration of leaking favorable information for political reasons, and took a bigger blow in the aftermath of the recent attacks on the U.S. Consulate in Benghazi, Libya.

Politicians and pundits accused him of covering up the true timeline of events that unfolded the night four Americans, including Ambassador Chris Stevens, were killed.

The retired four-star general was featured in Newsweek's special "Hero" issue just this week and provided a dozen tips on leadership in a piece penned by Broadwell, his biographer whom the FBI is reportedly investigating. "We all will make mistakes," tip number five began. "The key is to recognize them and admit them, to learn from them, and to take off the rear­ view mirrors—drive on and avoid making them again."

Here is Petraeus' letter in full:

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.