Washington (CNN) -- The career-ending affair that led to the resignation of CIA Director David Petraeus had its roots in a multi-year friendship, a flattering book and a young writer who was taken with the four-star general's leadership style.
The affair came to light during an FBI investigation of a complaint that author Paula Broadwell, 40, was allegedly sending harassing e-mails to another woman close to Petraeus, a U.S. official said. That probe also uncovered e-mails related to Gen. John Allen, the top U.S. commander in Afghanistan, and put his nomination for NATO commander on hold.
Here's a look at the anatomy of the affair:
Broadwell meets Petraeus when he speaks at Harvard, where she is a graduate student, according to preface of "All In" -- the book Broadwell wrote about the general's career and his impact on the military. She told the general about her research interests and he agreed to put her in touch with people studying the same issues. "I later discovered that he was famous for this type of mentoring and networking, especially with aspiring soldier-scholars," Broadwell wrote.
The Senate confirms Petraeus as the commanding general for U.S. troops in Iraq.
Broadwell begins her Ph.D. thesis on Petraeus' leadership skills. Some of the interviews were done via e-mail. Others were conducted as Broadwell occasionally ran with the physically fit four-star general, including one time with Petraeus and his team along the Potomac River.
Gen. John Allen begins his assignment as deputy commander of U.S. Central Command (CENTCOM) in Tampa, Florida, serving under Petraeus.
Petraeus is named commander of CENTCOM, based at MacDill Air Force Base near Tampa, where Jill Kelley and her husband attend social events alongside the area's military elite.
Petraeus is diagnosed with prostate cancer. Two months of radiation treatment at Walter Reed follow.
Broadwell moves with her husband Scott and two children to Charlotte, North Carolina.
Petraeus is tapped to replace Gen. Stanley McChrystal as the top commander in Afghanistan. He is confirmed by the Senate on June 30, and takes command on July 4 of that same year.
Allen is named as temporary CENTCOM commander, replacing Petraeus.
Broadwell decides to turn her research into a book and visits Afghanistan multiple times. "We had a relationship before I went there as far as this dissertation was concerned, so it just took it to another level," Broadwell told CNN's Brooke Baldwin in February 2012.
Allen succeeds Petraeus as the top American commander in Afghanistan.
August 31, 2011
Petraeus retires from the U.S. Army and is awarded the Army Distinguished Service Medal.
September 6, 2011
Petraeus is sworn in as new director of the Central Intelligence Agency. Broadwell keeps in contact with Petraeus and is later invited to his office for events.
Petraeus and Broadwell begin their affair about two months after he takes over at the CIA, according to a friend.
January 24, 2012
Broadwell's biography, "All In: The Education of General David Petraeus," is published.
In an interview with her hometown newspaper, the Bismarck Tribune, Broadwell describes Petraeus as an inspirational figure who always takes care of his subordinates.
An American official and a source close to Jill Kelley say Gen. John Allen and other officers begin receiving anonymous e-mails. The e-mails bear the handle "kelleypatrol -- or something similar," an official said, describing the missives as "a warning that Kelley was a seductress or something along those lines." That official called the e-mails "vaguely threatening, but above all weird." The source close to Kelley said Allen forwarded at least one of those e-mails to Kelley, thinking it's a joke. It mentions the upcoming meeting Kelley and Allen are due to have.
Kelley, 37, is an unpaid volunteer social liaison to Joint Special Operations Command, based in Tampa. Kelley and her husband have said they have been friends with the Petraeus family for more than five years.
Kelley and her husband begin to get e-mails from an unknown source, with four different e-mail addresses used, according to sources close to Kelley. Some are directed at her husband.
Kelley complains to an agent she knows in the FBI's Tampa office about threatening e-mails from an unidentified source. Tampa Division Cybersquad begins an investigation. The e-mails do not mention Petraeus, but a U.S. official tells CNN the nature of the messages was along the lines of "stay away from my guy." Another source says they referenced "the comings and goings of the generals and Ms. Kelley."
The identity of that FBI agent was a mystery for days after the scandal broke. He was identified November 14 by the general counsel for the Federal Law Enforcement Officers Association as Frederick Humphries.
Investigators and prosecutors determine they should investigate the case. An FBI agent asks Kelley for copies of the e-mails. A source close to Kelley says the e-mails being sent to her stop in mid-July.
Petraeus' relationship with Broadwell ends, according to friends close to Petraeus. The end of the affair was a mutual decision, says a friend.
Records of IP addresses are obtained, and Kelley is told that Broadwell (whom she does not know) is the sender of the anonymous e-mails. A U.S. official tells CNN that investigators "gained access" to Broadwell's computer. As part of the FBI's investigation, agents discover e-mails between Petraeus and Broadwell using Gmail accounts.
Petraeus tells Broadwell to stop sending harassing emails to Kelley, a U.S. official says. There is disagreement between sources exactly when this took place.
Broadwell -- by now a lieutenant colonel in the Army Reserve -- appears on a panel at the Aspen Institute.
"I was embedded with Gen. Petraeus in Afghanistan, and it was a little confusing to some of the folks there because I am also a military reservist with a top-secret FBI clearance and then some," Broadwell told the audience.
The FBI informs the Justice Department about the investigation. By this time, the FBI has long concluded there was no national security breach, but continues investigating whether Petraeus had any role in the harassing e-mails sent to Kelley. It is not clear when FBI Director Robert Mueller and Attorney General Eric Holder are informed.
Petraeus and Allen both write letters on behalf on Jill Kelley's sister Natalie Khawam, who is in the midst of a custody battle.
FBI investigators interview Broadwell. There's confusion over the date -- variously reported as some time in September, or as late as the week of October 21. A law enforcement source tells CNN's Fran Townsend that Broadwell gave authorities her computer at this time.
Broadwell talks to students at the University of Denver, and says: "The CIA annex (in Benghazi, Libya, during the attack on September 11, 2012) had actually had taken a couple of Libyan militia members prisoner and they think that the attack on the consulate was an effort to try to get these prisoners back. So that's still being vetted."
(On November 13 Sen. Susan Collins says she is surprised that Broadwell "had access to some classified information. We don't know whether that is true or not.")
Petraeus and Broadwell both attend the Office of Strategic Services Dinner in Washington. They do not sit together.
The FBI agent in Tampa -- Humphries -- who had been approached by Kelley reaches out to office of Rep. Dave Reichert, R-Washington, to express concern about lack of progress in the investigation. Reichert contacts House Majority Leader Eric Cantor, according to Cantor spokesman Doug Heye. Heye says Cantor had a conversation with the agent, described as a whistle-blower, about the affair and subsequently Cantor's chief of staff notified FBI Director Mueller.
"I received information from an individual that I had not met before and did not know," Cantor said later. "The information that was sent to me sounded as if there was a potential for a national security vulnerability."
FBI investigators interview Petraeus. There's disagreement over the date. The Washington Post reports it's October 29.
The FBI wraps up its case after interviewing Paula Broadwell a second time.
Broadwell offers CNN "a short essay on (Petraeus') leadership principles in light of" his 60th birthday. "Sorry I have been incognito-focused on the phd!" she adds.
November 6 (Election Day)
Petraeus' boss, Director of National Intelligence James Clapper, is informed of the probe in a phone call from the FBI at around 5 p.m. He speaks with Petraeus and advises him to resign.
Clapper notifies staff that Petraeus -- who turns 60 this day -- is considering resigning and why.
Newly re-elected President Barack Obama is informed. Petraeus visits the White House to hand in his resignation.
White House spokesman Jay Carney says later: "The president was certainly surprised when he was informed about the situation regarding General Petraeus on Thursday."
The president accepts Petraeus' resignation during a phone call. Petraeus steps down as director of the CIA, days before he was scheduled to testify before the Senate Intelligence Committee about the September 11 attack in Benghazi.
According to a congressional aide familiar with the matter, the House and Senate intelligence committees weren't informed that there was an FBI investigation before November 9.
Obama is also made aware of the investigation into Allen when the Department of Justice notifies White House counsel that there may be an issue associated with Allen's nomination, according to National Security Council spokesman Tommy Vietor.
Lawmakers complain in televised interviews that the FBI didn't alert them sooner to the investigation.
Sen. Dianne Feinstein, D-California, who chairs the Senate intelligence committee, says on Fox: "We received no advance notice; it was like a lightning bolt."
Kelley's identity is revealed by the Associated Press, and she issues a statement asking for privacy.
Kelley's statement: "We and our family have been friends with General Petraeus and his family for over five years. We respect his and his family's privacy and want the same for us and our three children."
That evening, the FBI notifies the Pentagon of its investigation into Allen's communications with Kelley, a senior official tells CNN.
Former Petraeus spokesman in Iraq Steve Boyland says Petraeus has told him meetings with Broadwell were "infrequent." He confirms Petraeus had a non-work e-mail account.
He also says Petraeus indicated "there was a possible obsession and she felt she was warding off the competition."
Boyland tells the Daily Mail that after the affair, "David and Paula were still in contact about Paula's dissertation."
Vietor says Fox is "flat out wrong" to suggest Brennan knew about the issue before November 7.
Broadwell retains D.C. criminal defense attorney Robert F. Muse.
At 9 p.m., Broadwell's home in Charlotte is searched to see what classified materials she might have. According to the Charlotte Observer, eight to 10 agents remove several cardboard boxes and bags.
"I don't think this is going to lead to any charges against her," a U.S. official tells CNN. He says an earlier search of Broadwell's computer revealed she had some classified material. Both she and Petraeus had said it did not come from Petraeus.
On Humphries, the FBI agent approached by Kelley, the same official says: "He was never on the case. He passed the information on to others who deal with cyber cases but he never worked the case and didn't receive information on the investigation as it proceeded."
Humphries sent shirtless photos to Kelley before this case ever began, according to an official.
On the same day, a senior U.S. defense official says the FBI uncovered between 20,000 and 30,000 pages of "potentially inappropriate" e-mails between Allen and Kelley. This is later clarified by a senior U.S. official -- many of the e-mails were group aliases rather than directly between Allen and Kelley.
John Nagl, who worked for Petraeus for years, says Petraeus insists he never shared classified information with Broadwell. Her access to Petraeus was "highly unusual but not illegal."
Sen. Susan Collins, R-Maine, says it is "absolutely imperative that General Petraeus come and testify" on Benghazi. "He has a great deal of information that we need." Feinstein agrees.
A U.S. official briefed on some of the details of the Allen e-mails suggests there is no criminal issue. While the documents warrant "further looking at....if there was a clear violation of the UCMJ we'd be handling it differently.'
A source close to Allen tells CNN's Nick Paton Walsh: "There is no affair. She (Kelley) is a bored, rich socialite involved with every single senior commander at CENTCOM, because she worked as an honorary consul."
"He gets an anonymous e-mail from Broadwell about Jill. He e-mails Jill to say that someone is threatening you," adds the official.
CENTCOM says Kelley "has no official position with U.S. Central Command. She is a volunteer and a private citizen, not an employee."
Kelley's access to visit MacDill AFB without an escort is suspended due to the investigation, a Defense Department official says. Kelley had been given special access to the base because of her position as a booster and promoter of programs to help U.S. troops, according to the official.
At a White House news conference, President Obama says he is unaware of any disclosure of classified information that could damage national security in the scandal that caused Petraeus' resignation.
FBI Director Robert Mueller makes unexpected appearance on Capitol Hill and meets lawmakers looking for answers on his agency's handling of the Petraeus investigation. He and his deputy meet Mike Rogers and Dutch Ruppersberger, as well as Sens. Feinstein and Chambliss. Chambliss later tells CNN he disagreed with the FBI explanation of how it handled protocols over the case.
CNN's Fran Townsend is told that any prosecution of Broadwell is unlikely: "It appears the information in question was not substantial -- it may have been a technical violation but was not egregious."
Paula Broadwell's security clearance is suspended.
The FBI agent approached by Kelly about the e-mails is identified as Frederick Humphries, 47, who had been friendly with the Kelleys for years. Lawrence Berger, counsel to Federal Law Enforcement Officers Association, says Humphries reported the information he received to the proper channels and had no further part in case.
A source close to Kelley says she has never "had any inappropriately sexual, romantic, physical relationship with either General Petraeus or General Allen."
Arrangements are made for Petraeus to testify on the Benghazi attack before House and Senate committees Friday.
Sourcing is CNN or public record if not noted otherwise. The FBI and Justice Department have not gone on the record. Much of the information for May 2012 and later comes from a variety of federal officials largely speaking on background; some comes from friends of Petraeus.
CNN's Alanne Orjoux, Dana Ford, Phil Gast, Michael Pearson, Carol Cratty, wires and staff contributed to this report.