CIA Director David Petraeus has resigned his position, citing personal reasons and an extramarital affair.

"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 said in a statement. "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."

Sources familiar with the investigation tell ABC News that Petraeus was having an affair with his biographer, Paula Broadwell.

The FBI was investigating Broadwell, for strange activity on the Internet when it discovered some emails that raised concerns, according to officials familiar with the probe.

Petraeus, a former Army general who led the surge into Iraq under former President Bush and also led U.S. troops in Afghanistan before taking over the CIA, is one of the most respected and influential generals of his time. His wife, Holly, has worked with the Obama administration to help military families.

He was scheduled to testify next week on Capitol Hill behind closed doors about the death of four Americans, including two working for the CIA. They died at the U.S. consulate in Benghazi, Libya, Sept. 11. Holes in security at the consulate have been the subject of an internal government investigation at the State Department and a congressional inquiry.

A U.S. official stressed that Petraeus' decision to step down had "absolutely nothing to do with Benghazi." Planned congressional hearings on the Benghazi incident will continue as planned with CIA Deputy Director Michael Morell filling in for Petraeus as acting director.

A senior U.S. official also told ABC News that Morell is expected to be named the permanent replacement atop the CIA.

President Obama reacted to the resignation with a written statement.

"David Petraeus has provided extraordinary service to the United States for decades," Obama said. "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."

There was no mention of the affair or the circumstances of Petraeus' resignation.

"Today, I accepted his resignation as director of the Central Intelligence Agency," Obama continued. "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," the president added.

The news shocked official Washington. Petraeus was perhaps the military's most-respected general of his generation. He was a problem-solver entrusted with key roles by two presidents from different parties.

Sen. Dianne Feinstein, D-Calif., chairman of the Senate Intelligence Committee, said she wished that Obama had not accepted Petraeus' resignation.

"I wish President Obama had not accepted this resignation, but I understand and respect the decision," Feinstein said in a statement. "This is an enormous loss for our nation's intelligence community and for our country."

In his statement, Petraeus said, "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," Petraeus added.

There were no further details about the circumstances surrounding the affair or Petraeus' departure.

No. 5 is notable in light of the news about his extramarital affair. "We all will make mistakes. 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."

The departure of Petraeus will add another hole to Obama's leadership team, which is expected to lose some high-profile faces in the coming weeks and months. Secretary of State Hillary Clinton is among the cabinet members who have said they will not stay in the administration for a second term. A hole at CIA will add yet another position that requires Senate confirmation to that list.

National Intelligence Director James Clapper praised Petraeus, who turned 60 two days ago, for his years of service.

"Whether he was in uniform leading our nation's troops in Iraq and Afghanistan, or at CIA headquarters leading the effort to generate intelligence used to keep our nation safe, Dave inspired people who had the privilege of working with him," Clapper said in a statement. "I have spent more than five decades serving our country -- in uniform and out -- and of all the exceptional men and women I have worked with over the years, I can honestly say that Dave Petraeus stands out as one of our nation's great patriots."