Updated

The resignation of CIA Director David Petraeus has brought a sudden and unexpected end to the public career of a four-star general who led U.S. troops in Afghanistan and Iraq and was thought to be a potential candidate for president.

Petraeus admitted to an extramarital affair in tendering his resignation, which President Barack Obama accepted Friday.

Petraeus carried on the affair with his biographer Paula Broadwell, a reserve Army officer, according to several U.S. officials with knowledge of the situation. They spoke anonymously because they were not authorized to discuss publicly the investigation that led to the resignation.

The FBI discovered the relationship by monitoring Petraeus' emails, after being alerted Broadwell may have had access to his personal email account, two of the officials said.

Broadwell did not respond to voice mail or email messages seeking comment. Broadwell's biography, "All In: The Education of General David Petraeus," was written with Vernon Loeb, a Washington Post editor, and published in January.

Lawmakers from both parties joined Obama in praising Petraeus. Obama said in a statement that Petraeus had provided "extraordinary service to the United States for decades" and had given a lifetime of service that "made our country safer and stronger."

CIA Deputy Director Michael Morell will serve as acting director, Obama said. Morell was the key CIA aide in the White House to President George W. Bush during the Sept. 11, 2001, terror attacks.

"I am completely confident that the CIA will continue to thrive and carry out its essential mission," Obama said.

The resignation comes at a sensitive time. The administration and the CIA have struggled to defend security and intelligence lapses before the attack that killed the U.S. ambassador to Libya and three others. It was an issue during the presidential campaign that ended with Obama's re-election Tuesday.

The CIA has come under intense scrutiny for providing the White House and other administration officials with talking points that led them to say the Benghazi attack was a result of a film protest, not a militant terror attack. It has become clear that the CIA was aware the attack was distinct from the film protests roiling across other parts of the Muslim world.

Morell rather than Petraeus now is expected to testify at closed congressional briefings next week on the assault on the consulate in Benghazi, which occurred on the 11th anniversary of the 9/11 attacks.

Petraeus, who turned 60 on Wednesday, has been married for 38 years to Holly Petraeus, whom he met when he was a cadet at the U.S. Military Academy at West Point, N.Y. She was the daughter of the academy superintendent. They have two children, and their son led an infantry platoon in Afghanistan.

The retired general told his staffers in a statement that he was guilty of "extremely poor judgment" in engaging in the affair. "Such behavior is unacceptable, both as a husband and as the leader of an organization such as ours." He said he had offered his resignation to Obama on Thursday and the president accepted it Friday.

Administration officials said the White House was first notified about the Petraeus affair on Wednesday, the day after the election. Obama, who returned to the White House that evening after spending Election Day in Chicago, wasn't informed until Thursday morning.

For the director of the CIA, being engaged in an extramarital affair is considered a serious breach of security and a counterintelligence threat. If a foreign government had learned of the affair, the reasoning goes, Petraeus or Broadwell could have been blackmailed or otherwise compromised. Military justice considers conduct such as an extramarital affair to be possible grounds for court-martial.

Failure to resign also could create the perception for the rank and file that such behavior is acceptable.

At FBI headquarters, spokesman Paul Bresson declined to comment on the information that the affair had been discovered in the course of an investigation by the bureau.

Holly Petraeus is known for her work helping military families. She joined the new Consumer Financial Protection Bureau to set up an office dedicated to helping service members with financial issues.

Though Obama made no direct mention of Petraeus' reason for resigning, he offered his thoughts and prayers to the general and his wife, saying that Holly Petraeus had "done so much to help military families through her own work. I wish them the very best at this difficult time."

Petraeus, who became CIA director in September 2011, was known as a shrewd thinker and hard-charging competitor. His management style was recently lauded in a Newsweek article by Broadwell.

The article listed Petraeus' "rules for living." No. 5 was: "We all make mistakes. The key is to recognize them, to learn from them, and to take off the rear view mirrors — drive on and avoid making them again."

In the preface to her book, Broadwell said she first met Petraeus in the spring of 2006. She was a graduate student at the Kennedy School of Government at Harvard, and he was visiting the university to discuss his experiences in Iraq and a new counterinsurgency manual he was working on.

She had graduated from West Point with academic, fitness, and leadership honors, according to a biography posted on her publisher's website that lists authors available for speaking engagements.

The biography said she had "lived, worked, or traveled in more than 60 countries during more than 15 years of military service and work in geopolitical analysis and counterterrorism and counterinsurgency operations." It said she had spent time with the U.S. intelligence community, U.S. Special Operations Command and FBI Joint Terrorism Task Forces.

Harvard invited some students to meet with Petraeus, and Broadwell was among them because of her military background, which she wrote included being recalled to active duty three times to work on counterterrorism issues after the Sept. 11 attacks.

"I had since joined the Army Reserve and begun graduate studies with the intent of returning either to active duty or to the policy world," she wrote in the preface. She introduced herself and described her research interests. He gave her his card and offered to connect her with others working on the same issues.

"I later discovered that he was famous for this type of mentoring and networking, especially with aspiring soldier-scholars. He immediately responded to the email, inviting me to bounce ideas off him. I took full advantage of his open-door policy to seek insight and share perspectives," Broadwell wrote.

In 2008, she wrote, she was pursuing a Ph.D. in public policy and embarking on a case study of Petraeus' leadership. At one point, she said, he invited her for a run along the Potomac River with his team while he was in Washington.

"I'd earned varsity letters in cross-country and indoor and outdoor track and finished at the top of my class for athletics at West Point; I wanted to see if he could keep stride during an interview. Instead it became a test for me." He eventually increased the pace "until the talk turned to heavy breathing and we reached a 6-minute-per-mile pace. It was a signature Petraeus move. I think I passed the test, but I didn't bother to transcribe the interview."

After Obama put Petraeus in charge in Afghanistan in 2010, Broadwell decided to expand her research into an authorized biography.

Broadwell made many trips to Afghanistan, with unprecedented access to Petraeus, and also spent time with his commanders across the country. When Petraeus took the job at the CIA, she remained in close contact with him, sometimes invited to his office for events like his meeting with Hollywood actress Angelina Jolie.

With the book done, she told friends she had been concentrating on turning part of her research on Petraeus into a dissertation, to complete her doctorate.

Petraeus, in his email, told his CIA employees that he treasured his work with them "and I will always regret the circumstances that brought that work with you to an end."

The director of national intelligence, James Clapper, said Petraeus' departure represented "the loss of one of our nation's most respected public servants. From his long, illustrious Army career to his leadership at the helm of CIA, Dave has redefined what it means to serve and sacrifice for one's country."

Other CIA directors have resigned under unflattering circumstances. CIA Director Jim Woolsey left over the discovery of a KGB mole, and director John Deutch left after the revelation that he had kept classified information on his home computer.

Before Obama brought Petraeus to the CIA, he was credited with salvaging the U.S. war in Iraq.

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

President George W. Bush sent Petraeus to Iraq in February 2007, at the peak of sectarian violence, to turn things around as head of U.S. forces. He oversaw an influx of 30,000 U.S. troops and moved troops out of big bases so they could work more closely with Iraqi forces scattered throughout Baghdad.

Petraeus' success was credited with paving the way for the eventual U.S. withdrawal.

After Iraq, Bush made Petraeus commander of U.S. Central Command, overseeing all U.S. military operations in the greater Middle East, including Afghanistan and Pakistan.

When the top U.S. commander in Afghanistan, Gen. Stanley McChrystal, was relieved of duty in June 2010 for comments in a magazine story, Obama asked Petraeus to take over in Kabul and the general quickly agreed.

In the months that followed, Petraeus helped lead the push to add more U.S. troops to that war and dramatically boost the effort to train Afghan soldiers and police.

The Senate and House intelligence committees were briefed on Petraeus' resignation only after the news was reported in the media, said a congressional staffer, speaking anonymously because the staffer was not authorized to publicly discuss the sensitive briefings.

House Homeland Security Chairman Peter King, R-N.Y., said he regretted Petraeus' resignation, calling him "one of America's most outstanding and distinguished military leaders and a true American patriot."

Senate Intelligence Committee Chairman Dianne Feinstein, D-Calif., also regretted the resignation but gave Morell high marks, too.

Morell had served as deputy director since May 2010, after holding a number of top roles, including director for the agency's analytical arm, which helps feed intelligence into the president's daily brief. He also worked as an aide to former CIA Director George Tenet.

"I wish President Obama had not accepted this resignation," Feinstein said of Petraeus, "but I understand and respect the decision."

___

Associated Press writers Wendy Benjaminson, Ken Thomas, Donna Cassata, Kimberly Dozier, Connie Cass, Eileen Sullivan, Pete Yost and Anne Flaherty contributed to this report.