By Kate Holton and Michael Holden

LONDON (Reuters) - Rebekah Brooks and Andy Coulson, former editors of Rupert Murdoch's now-defunct News of the World tabloid, had a six-year affair at the time their reporters hacked phone messages of politicians and royalty, a London court heard on Thursday.

Revealing their close ties, prosecutor Andrew Edis said the intimacy of their relationship indicated both knew as much as the other about the criminal activities of senior journalists on the paper.

Brooks and Coulson are on trial accused of conspiring to hack into phones of high-profile public figures or those close to them and also making illegal payments to public officials, charges they deny.

"It isn't simply that there was an affair. What effect did it have?" Edis told the court. "It isn't to do with whether they had sexual relations with one another ...(but) how close were they? They were very close indeed."

Coulson went on to become the chief media spokesman for Prime Minister David Cameron while Brooks, a close confidante to Murdoch, went on to be chief executive of News International, the tycoon's British newspaper group.

The revelation of the affair is likely to bring more embarrassment to Cameron, who has long been accused by critics of being too close to Murdoch's News Corp media empire.

Murdoch owns The Sun and Times papers and 39 percent of pay-TV group BSkyB, which opponents say enables him to wield too much political influence in Britain.

A public inquiry into media ethics, sparked by the hacking scandal, revealed how Cameron regularly texted or met Brooks for dinner at their country homes.

Edis told a hushed Old Bailey court the affair went to the heart of the case. It began in 1998 and continued for at least six years, during which Brooks married her first husband, TV soap actor Ross Kemp, in 2002. Coulson himself married in 2000.

They showed little reaction to the revelation as they sat side-by-side in the glass dock along with six other defendants. Sitting five seats away was Brooks's second husband Charlie, whom she married in 2009 and who is also on trial, accused of helping his wife try to hide evidence from police.

Brooks and Coulson's relationship was discovered after police found a document containing a 2004 letter on a computer at Brooks's London home. Brooks wrote the letter to Coulson after he tried to break off the relationship, something which had obviously caused her a great deal of grief, Edis said.

"I TELL YOU EVERYTHING"

"The fact is 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," the letter said, according to Edis who read it out to the jury of nine women and three men.

"In fact without our relationship in my life I am not sure I will cope."

Edis said the affair had great significance because it implicated Brooks in the hacking of the phone belonging to a missing schoolgirl, Milly Dowler, who was later found murdered.

Private detective Glenn Mulcaire, who worked for the News of the World, has admitted hacking voicemail messages on Dowler's phone after she disappeared in March 2002.

The court heard the paper printed stories based on these hacks when Coulson, who was deputy editor, was in charge while Brooks was on holiday in Dubai. Phone records showed that she was in regular contact with both him and the newsroom.

"It's simply incredible that the editors did not know what was being done that week," Edis said.

It was the 2011 revelation about the Dowler hacking that provoked a public storm and led Murdoch to close down the 168-year-old tabloid, then Britain's biggest-selling paper.

A public inquiry ordered in its wake by Cameron embarrassed senior politicians and police who were shown to have very close links to press barons including the 82-year-old Murdoch.

CONFIDENCE IN THE SOURCE

The jury was later played an audio recording of Coulson confronting former Labour minister David Blunkett in 2004 with revelations of an affair which Edis said had come about from phone-hacking. Coulson was heard saying he had full confidence in the source of the story, which he would not reveal.

The story first appeared in the News of the World, which Coulson was by then editing, and the following days similar stories appeared in Sun, which was being edited by Brooks.

"It tells us Mr. Coulson had asked himself and answered the editor's question; how do I know this is true. It was hacked voicemail messages, that's how he knew," the prosecutor said.

"Mrs. Brooks ... would need to know the answer too. And the answer would be the same: hacked voicemail messages."

Earlier on Thursday, the jury heard that Brooks and Coulson had authorized huge payments to Mulcaire at a time when the News of the World was drastically cutting costs.

Brooks and Coulson ordered senior staff to slash budgets but allowed him to be paid about 100,000 pounds ($161,000) a year.

"What was so special about him?" Edis asked the jury of Mulcaire. "Well, what was so special about him was that he was doing phone-hacking."

In a bid to get ahead on salacious front-page stories, Mulcaire repeatedly hacked the phones of senior politicians, royalty and even rival journalists to get big stories, the jury heard. The trial is expected to last for six months.

(Additional reporting by Josh Franklin; Editing by Sonya Hepinstall, Estelle Shirbon and Guy Faulconbridge)