WASHINGTON – CIA Director David Petraeus resigned Friday and admitted to having an extramarital affair, bringing a shocking end to his brief tenure at the spy agency and highly decorated national security career.

The affair came to light as part of an FBI investigation into a potential security breach involving Petraeus’ emails, according to federal law enforcement officials and a former senior intelligence official. The investigation uncovered emails describing an affair between Petraeus and Paula Broadwell, a former military officer and co-author of a glowing biography of Petraeus, according to two law enforcement officials who were briefed on the investigation.

Petraeus, a retired four-star Army general who once was seen as a potential presidential candidate, met with President Obama on Thursday and said he intended to step down because of the affair, Obama administration officials said. The president accepted his resignation Friday.

“After being married for over 37 years, I showed extremely poor judgment by engaging in an extramarital affair,” Petraeus said in a statement distributed to the CIA work force Friday.

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

A senior administration official said the White House learned only Wednesday that Petraeus had a potentially serious problem. The official said that Petraeus telephoned Thomas Donilon, the national security adviser, early Thursday and asked to meet with Obama.

The investigation is not expected to result in any accusations of criminal wrongdoing by Petraeus or Broadwell, according to the two law enforcement officials, who spoke on condition that their names be withheld because they were not authorized to speak publicly.

The sudden departure of Petraeus created turmoil in the administration’s national security team just days after the president’s re-election. That team was expected to see a series of changes in the coming months, but many believed that Petraeus would remain in position.

In a statement, Obama said Petraeus has “provided extraordinary service to the United States for decades,” adding that “through his lifetime of service David Petraeus has made our country safer and stronger.”

The statement did not directly address Petraeus’s reason for resigning, but the president said that his “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.”

Holly Petraeus is an assistant director of the U.S. Consumer Financial Protection Bureau, where she is charged with advocating on behalf of service members and their families. She and her husband met in 1973 at the U.S. Military Academy at West Point, where her father was superintendent.

Broadwell, who also is married, is a West Point graduate and a research associate at Harvard University. She is the co-author of “All In: The Education of General David Petraeus.” (The book’s co-author was Vernon Loeb, local editor at The Washington Post.)

In earlier interviews, Broadwell described meeting Petraeus in 2006 at Harvard, where she was working on a dissertation about leadership. She said they soon started emailing and discussing her research.

In the preface to the book, Broadwell said that after Obama picked Petraeus to lead U.S.forces in Afghanistan in June 2010, he invited her to Kabul and she decided to turn her dissertation into a biography. She made repeated trips to Afghanistan to spend time observing Petraeus.

In describing Petraeus in a CBS News interview two months ago, she said: “He, at the end of the day, is human and is challenged by the burdens of command. … So, he has this mask of command –you think he’s really confident — but I got to see a more personal side. He’s confident, but he’s also very compassionate about the loss of troops and sacrifices we’re making in Afghanistan.”

Petraeus was due to testify next week on Capitol Hill in hearings on the deaths of four Americans, including the U.S. ambassador and two CIA security officers, in Libya in September.

U.S. officials insisted that the controversy surrounding the attack – and the administration’s shifting accounts of it – played no role in Petraeus’s decision to resign. His 14-month tenure as CIA director is one of the shortest in agency history.