WASHINGTON -- The FBI investigation that led to the resignation of David Petraeus as CIA director Friday began with a complaint several months ago about "harassing" emails sent by Paula Broadwell, Petraeus' biographer, to an unidentified third person, a government official briefed on the case said Saturday.

When FBI agents following up on the complaint began to examine Broadwell's emails, they discovered exchanges between her and Petraeus that revealed that they were having an affair, said the official, who spoke of the investigation on the condition of anonymity.

The person who complained about harassing messages from Broadwell, according to the official, was not a family member or a government official. One congressional official who was briefed on the matter Friday said senior intelligence officials had explained that the FBI investigation "started with two women."

"It didn't start with Petraeus, but in the course of the investigation they stumbled across him," said the congressional official, who said the intelligence officials had provided no other information about the two women or the focus of the inquiry. "We were stunned."

Petraeus said in a statement that he was resigning after 14 months as head of the CIA because he had shown "extremely poor judgment" in engaging in the affair. He has been married for 38 years.

Neither the congressional intelligence committees nor the White House learned of the investigation or the link to Petraeus until last week, officials said. Neither did Petraeus' boss, James Clapper Jr., the director of national intelligence.

A senior intelligence official said Saturday that Clapper had learned of Petraeus' situation only when the FBI notified him about 5 p.m. Tuesday. That night and the next day, the official said, the two men discussed the situation, and Clapper told Petraeus "that he thought the right thing to do would be to resign," the intelligence official said.

Clapper notified the president's senior national security staff late Wednesday that Petraeus was considering resigning because of an extramarital affair, the official said.

Some congressional staff members said they believed that the bureau should have informed at least the Republican and Democratic leaders of the House and Senate intelligence committees about the unfolding inquiry. The committees are likely to demand an explanation of why they were not told.

"Why didn't the FBI tell us?" said Rep. Peter King, a New York Republican on the House Intelligence Committee. "Why was the FBI investigating the CIA and this was involving a compromised computer of the director of the CIA, nobody told the president or the White House?"

White House officials said they were informed Wednesday night that Petraeus was considering resigning because of an extramarital affair. Thursday morning, just before a staff meeting at the White House, Obama was told.

That afternoon, Petraeus went to see Obama and informed him that he strongly believed he had to resign. Obama did not accept his resignation right away, but Friday, he called Petraeus and accepted it.

The government official dismissed a range of speculation that the FBI inquiry might have focused on leaks of classified information to the press or even foreign spying. "People think that because it's the CIA director, it must involve bigger issues," the official said. "Think of a small circle of people who know each other."

The FBI investigators were not pursuing evidence of Petraeus' marital infidelity, which would not be a criminal matter, the official said. But their examination of his emails, most or all of them sent from a personal account and not from his CIA account, raised the possibility of security breaches that he needed to address directly.

"Alarms went off on larger security issues," the official said. As a result, FBI agents spoke with the CIA director about two weeks ago, and he learned in the discussion, if he was not already aware, that they knew of his affair with Broadwell, the official said.

Web-based email like Gmail and Yahoo Mail can be quite vulnerable to hacking, and it is possible that FBI experts were studying whether Petraeus' accounts had been compromised. Any possibility that hackers could use the CIA director's email as a route to break into sensitive government computer systems would be an obvious concern.

But the fears of bigger security problems proved unjustified, and the security questions were resolved, the official said.

But there are still several unanswered questions surrounding the circumstances of the FBI investigation and about the affair between Petraeus and Broadwell, officials said Saturday.

It is not clear yet, for instance, when Attorney General Eric Holder Jr. or Robert Mueller III, the director of the FBI, became aware that the FBI's investigation into Broadwell's emails had run across Petraeus.