Updated

CIA Director David Petraeus resigned Friday after admitting to an extramarital affair -- an affair with his biographer that was revealed over the course of an FBI investigation, Fox News has learned.

The FBI had been investigating an unrelated and much broader case before stumbling on the affair. Fox News has learned that during the course of this investigation, the name of biographer Paula Broadwell came up. The FBI followed that lead and in doing so, uncovered his affair with her. The FBI for some time was concerned that perhaps Petraeus was some sort of victim, but there has been no evidence discovered to back up such concerns.

Broadwell co-wrote Petraeus' biography, "All In."

Petraeus met with President Obama on Thursday before submitting his letter of resignation, which the president accepted.  In a message to staff, Petraeus said he asked "to be allowed" to step down.

"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," the retired four-star general said. "This afternoon, the President graciously accepted my resignation."

More On This...

The move comes amid the unfolding controversy surrounding the attack on the U.S. Consulate in Libya. Scrutiny has fallen on a range of agencies including the CIA, and the director had been set to testify at hearings next week -- he is no longer expected to do so. But Petraeus, in his resignation message, cited strictly "personal reasons" surrounding the affair.

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

Obama, in a written statement, said Petraeus provided an "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," Obama said. He said he has named Michael Morell, the agency's deputy director, to serve as acting director.

The FBI investigation began when an individual reported suspicious and strange emails allegedly from Broadwell.  The FBI determined that Broadwell allegedly emailed a number of government employees, and it tried to determine if any of its employees were being stalked.  The affair was unveiled, as a result, with Petraeus being one of these employees.

The FBI eventually determined no criminal acts had been committed.

The decision abruptly ends the public-service career of one of the military's most vaunted leaders. He led the surge in Iraq, and was later tapped to lead U.S. and NATO forces in Afghanistan -- following two years at the helm of U.S. Central Command. In April 2011, Obama again tapped Petraeus to lead the CIA.

He leaves just three days after Obama was elected to a second term, and amid a challenging environment for the country's intelligence community -- which is dealing with not just rogue nations like Iran but a changing landscape elsewhere as a result of the Arab Spring. It has been confirmed that the U.S. compound that was attacked in Libya housed CIA operatives as well as State Department staff.

The intelligence community subsequently came under scrutiny when some officials suggested the administration initially claimed the attack was "spontaneous" only because of the intelligence assessments at the time.

Director of National Intelligence James Clapper said Friday that Petraeus' resignation "represents the loss of one of our nation's most respected public servants."

Lawmakers on Capitol Hill expressed similar sentiments.

"General David Petraeus will stand in the ranks of America's greatest military heroes. His inspirational leadership and his genius were directly responsible -- after years of failure -- for the success of the surge in Iraq," Sen. John McCain, R-Ariz., said. "General Petraeus has devoted his life to serving the country he loves, and America is so much the better for it."

Fox News' Mike Levine contributed to this report.