The collapse of the impressive career of CIA Director David H. Petraeus was triggered when a woman with whom he was having an affair sent threatening e-mails to another woman close to him, according to three senior law enforcement officials with know­ledge of the episode.

The recipient of the e-mails was so frightened that she went to the FBI for protection and help tracking down the sender, according to the officials. The FBI investigation traced the threats to Paula Broadwell, a former military officer and a Petraeus biographer, and uncovered explicit e-mails between Broadwell and Petraeus, the officials said.

The woman who received the e-mails was Jill Kelley in Tampa, Fla., according to law enforcement officials. The nature of her relationship with Petraeus is unknown.

When Petraeus’s name surfaced, FBI investigators were concerned that the CIA director’s personal e-mail account had been hacked and that national security had been threatened. The officials said further investigation, including FBI interviews with Broadwell and Petraeus, led to the discovery that the two were engaged in an affair.

The law enforcement officials said the e-mails indicated that Broadwell perceived the other woman as a threat to her relationship with Petraeus.

Attempts to reach Broadwell and her relatives have been unsuccessful, and she has not made a public statement since she was linked with Petraeus on Friday.

All three senior officials who described the impetus for the investigation spoke on the condition of anonymity because aspects of the inquiry are ongoing.

Petraeus, a retired four-star Army general who was once seen as a potential presidential candidate, said Friday that he was resigning as CIA chief because he had been involved in an extramarital affair. He has been married for 38 years and has two grown children, though he said in his resignation statement to CIA colleagues that he had been married “over 37 years.”

Broadwell is married and has two young children.

In an e-mail sent to a longtime friend Friday night, Petraeus expressed regret for letting down his family and the nation. The friend, who described the contents of the e-mail on the condition of anonymity, said Petraeus conveyed profound remorse in the message.

“He was deeply sorry for the pain he has caused his family,” the friend said. “He also noted how much he loved his job at the agency. He said he really relished the intellectual challenge there.”

Other details emerged Saturday indicating that the Petraeus allegations became a secret election-night drama for the Obama administration. That evening, the Justice Department informed the director of national intelligence, James R. Clapper Jr., that their investigation had unearthed compromising information about the CIA director, according to a senior U.S. intelligence official.

Clapper then spoke with Petraeus and urged him to resign, notifying the White House the next day. That sequence has become a source of controversy, raising questions among some members of Congress about why key intelligence committees were not notified earlier and why the FBI waited before informing the administration about a probe that had stumbled onto embarrassing details about the CIA chief.

The law enforcement officials did not provide an exact timeline for the investigation, but they said the inquiry started several months ago. They said investigators thought they were dealing with a routine harassment case until some communications were traced to a private e-mail account belonging to Petraeus.

The sexually explicit nature of the communications caused investigators to suspect that someone had broken into Petraeus’s e-mail account, leading to concerns about potential national security breaches, according to the officials. As the investigation proceeded and more evidence emerged, including Broadwell’s role, FBI investigators realized they had uncovered an affair between Petraeus and Broadwell, the officials said.

The e-mails from Broadwell indicated that she thought the other woman was becoming involved with Petraeus, according to the officials. They said the e-mails were “threatening and harassing” but not specific enough to warrant criminal charges.

One of the officials said that the recipient of the e-mails complained to Petraeus about them and that the FBI later obtained e-mails between Petraeus and Broadwell in which they discussed the harassment.

The investigators first interviewed Petraeus about two weeks ago, the officials said. They reviewed the evidence with him but did not suggest that he should resign or that he would be charged with a crime, according to the officials.

One of the officials said Justice Department officials were unclear on what steps to take after they concluded that there would be no charges against the CIA director or Broadwell and that there had been no breach of national security.

“What was our responsibility?” said one of the officials. “We were in an area where we’d never been before.”

The notification finally came Tuesday evening, while polls were still open across the country in an election that would return President Obama to office for four more years.

“Director Clapper learned of the situation from the FBI on Tuesday evening around 5 p.m.,” a senior U.S. intelligence official said. “In subsequent conversations with Director Petraeus, Director Clapper advised Director Petraeus to resign.”

The official declined to say whether Petraeus had considered resigning at that point, but he said it was quickly clear to Clapper that stepping down was “the right thing to do.”

The official said that Clapper has been fully briefed on the FBI investigation and has not called for his office or the CIA to conduct a follow-up probe or damage assessment — indicating that Clapper does not see the case as a security threat.

“There are no investigations beyond” that initiated by the FBI, the intelligence official said, speaking on the condition of anonymity because of the sensitivity of the matter. The official would not address why the Office of the Director of National Intelligence and others were not notified earlier of the FBI investigation and its link to Petraeus.

The emerging details suggest that Petraeus was not involved in the decision to notify the White House that he had been ensnared in an FBI probe.

Instead, it was Clapper who told the White House late Wednesday, with Obama learning about it a day later. A senior administration official defended the decision not to notify the president earlier, saying that staff “needed to get their arms around” the matter before briefing Obama, who had returned from his election trip to Chicago on Wednesday night.

Obama summoned Petraeus to the White House on Thursday and “made the decision alone overnight” to accept his CIA director’s resignation, the official said.

“Petraeus was pretty clear in his intent to resign,” the official said. He “wasn’t looking to be talked out of it.” Friday morning, Obama notified his senior staff, then made two calls, first to Petraeus and then to the man now serving as acting CIA director, Michael J. Morell.

CIA officials declined to discuss how events unfolded inside the agency’s headquarters, but a senior U.S. intelligence official said that “this was a sudden announcement internally as well as externally.”

Petraeus has already stopped duties as director and begun a transition process that will determine, among other things, how much personal security he will keep as a private citizen.

White House and intelligence officials said again Saturday that there was no connection between Petraeus’s resignation and the controversy surrounding the deaths of four Americans in Libya in September.

Still, the timing of Petraeus’s departure, and the apparent decision by the FBI to withhold information about its probe, is already coming under question and criticism from Capitol Hill.

Senior Senate aides said that the Senate intelligence committee did not learn of the matter until Friday, just hours before the Petraeus resignation was announced. Even then, the first word came from news reports, prompting the committee to press the White House and CIA for answers.

By law, agencies are required to notify the committees of significant intelligence developments. Some questioned how a probe that turned up compromising information about the CIA director did not qualify.

“This is a very personal matter, not a matter of intelligence,” the senior U.S. intelligence official said. “There are protocols for this. I would imagine things have to cross a certain threshold before they are reportable.”