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 today.

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.

Mr Coulson went on to become the chief media spokesman for prime minister David Cameron and the revelataion is likely to bring more embarrassment to Cameron, who has long been accused by critics of being too close to Mr Murdoch’s media empire.

Ms Brooks, a close confidante to Mr Murdoch, was running the media tycoon’s British newspaper arm from 2009 to 2011. Mr Edis said the affair between Ms Brooks and Mr 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 Ms 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 Ms Brooks to Mr Coulson said, according to Mr Edis who read it out to the jury of nine women and three women.

The court heard that the letter was apparently written by Ms Brooks in response to Mr Coulson trying to end the affair.

Mr Edis told jurors he was not revealing the affair to deliberately intrude into their privacy or to make a “moral judgment”.

“But Mrs Brooks and Mr Coulson are charged with conspiracy and, when people are charged with conspiracy, the first question a jury has to answer is how well did they know each other? How much did they trust each other?

“And the fact that they were in this relationship which was a secret means that they trusted each other quite a lot with at least that secret and that’s why we are telling you about it.”

He said the revelation was likely to attract a “great deal of publicity” and may draw some “unfair, unkind and unnecessary” comment.