A prosecutor electrified Britain's phone hacking trial Thursday by revealing that Rebekah Brooks and Andy Coulson -- the two most senior U.K. tabloid editors accused of illegal eavesdropping and bribery -- had a secret affair lasting at least six years.

Prosecutor Andrew Edis said the relationship between the two powerful editors -- both former top Rupert Murdoch aides and associates of Prime Minister David Cameron -- goes to the heart of the case's key question: Who knew what during years of illicit activity at Murdoch's News of the World and Sun tabloids?

The fact they had an affair and kept it secret "means they trusted each other a lot," Edis said. He said there was "absolute confidence between the two of them" about issues at their work.

"Through the relevant period, what Mr. Coulson knew Mrs. Brooks knew too, and what Mrs. Brooks knew Mr. Coulson knew too, because it's clear ... that as at February 2004 they had been having an affair which had lasted at least six years," he said.

The two enjoyed close ties to Britain's media and political elite. Brooks has been friends with Cameron and Coulson served as his communications director before and after Cameron's election as prime minister in 2010.

Edis said their affair started in about 1998 and covered the period when Brooks was News of the World editor and Coulson her deputy -- including the period in 2002 when the newspaper hacked into the phone of 13-year-old Milly Dowler, who was later found murdered.

The prosecution contends that Brooks and Coulson must have sanctioned the hacking.

Brooks and Coulson, both 45, Brooks' current husband Charles Brooks, and five others are on trial in the first major criminal case spawned by the revelation of the paper's eavesdropping. The eight defendants all deny a variety of charges related to phone hacking, bribing officials and obstructing a police inquiry.

The phone hacking scandal forced Murdoch to shut the 168-year-old News of the World, triggered police inquiries into phone hacking and bribery by journalists and has created intense pressure on Britain's freewheeling tabloid press to mend its ways.

In his opening statement Thursday, Edis laid out the prosecution's claim that Brooks, Coulson and other senior editors must have known about phone hacking that went on for years at the News of the World and its sister paper, The Sun.

He said News of the World journalists, with consent from the tabloid's top editors, colluded to eavesdrop on the voice mail messages of phones of politicians, royalty, celebrities and even rival reporters in a "frenzy" to get scoops.

Detailed records shown to jury

He showed the jury detailed records -- audio recordings, notes and email trails -- of what he said were phone-hacking assignments from the News of the World to private investigator Glenn Mulcaire. The targets included former Labour Cabinet ministers Tessa Jowell, John Prescott and David Blunkett - whose own affair was revealed in a sting on his girlfriend's phone.

Mulcaire also targeted royal family member Lord Frederick Windsor, two journalists from the rival Mail on Sunday, and Dowler's phone, the prosecutor said.

Mulcaire was jailed briefly in 2007 for hacking the voicemails of royal aides. He has now pleaded guilty to new charges, including hacking Dowler's phone.

Three former News of the World news editors have also pleaded guilty, but those who were above them, including Brooks and Coulson, have denied knowing about the hacking.

Edis said that claim was barely credible. Mulcaire was paid about 100,000 pounds a year under both Brooks and Coulson for his services.

"Did nobody ever ask, `What are we paying this chap for?'" he said. "Somebody must have decided that what he was doing was worth an awful lot of money. Who was that?"

The prosecutor's forensic analysis of the phone-hacking trail was overshadowed by his revelation about Coulson and Brooks' private lives. The two defendants, sitting side-by-side in the dock at the rear of the court, did not visibly react as the lawyer spoke.

Edis said the revelation was "likely to attract a great deal of publicity," some of it "unfair, unkind and unnecessary," but insisted it was relevant.

He said the affair was revealed when police investigating phone hacking in 2011 found an intimate letter written by Brooks to Coulson on a computer in her London home.

He said the 2004 letter was Brooks' reply to Coulson's attempt to end the affair. It's not clear whether it was ever sent.

"You are my very best friend. I tell you everything, I confide in you, I seek your advice, I love you, care about you, worry about you, we laugh and cry together," Brooks wrote in the letter read by Edis in court. "In fact, without our relationship in my life I am really not sure I will cope."

Brooks edited the News of the World from 2000 to 2003, then went on to edit The Sun, and later became the chief executive of Murdoch's British newspaper division. Coulson edited the News of the World from 2003 to 2007.

Brooks married soap-opera star Ross Kemp in 2002. They later divorced and she married horse trainer Charles Brooks in 2009. Coulson married in 2000.

The affair apparently ended before Coulson became communications director for Conservative party leader Cameron in 2007, a job he continued when Cameron was elected prime minister in 2010.

Both he and Brooks resigned from their jobs after the hacking scandal exploded in 2011.