LONDON (Reuters) - Rebekah Brooks and Andy Coulson, two former editors of Rupert Murdoch's now defunct News of the World tabloid, were having an affair at the time their reporters are accused of hacking into phones, a court heard on Thursday.

Prosecutor Andrew Edis said the closeness of their relationship showed that both knew as much as each other how staff at the tabloid were operating. Both have denied conspiring to hack into phones or making illegal payments to public officials.

Coulson went on to become the chief media spokesman for Prime Minister David Cameron and the revelation is likely to bring more embarrassment to Cameron, who has long been accused by critics of being too close to Murdoch's media empire.

Brooks, a close confidante to Murdoch, was running the media tycoon's British newspaper arm from 2009 to 2011. Edis said the affair between Brooks and Coulson had lasted for at least six years.

The relationship had been discovered after police found a word document containing a 2004 letter on a computer stored at Brooks's home.

"You are my best friend ... I tell you everything, I confide in you ... I love you, I care about you," the letter from Brooks to Coulson said, according to Edis who read it out to the jury of nine women and three women.