Rebekah Brooks had a secret affair for at least six years with Andy Coulson, her successor as editor of the News of the World, it emerged at the Old Bailey on Thursday.

The jury in the phone-hacking trial was told that the clandestine relationship took place between 1998 and 2004, covering much of the period when Brooks and Coulson are said to have been involved in a criminal conspiracy to hack phones.

Andrew Edis QC, for the crown, said the revelation was not designed to invade their privacy but to help the prosecution demonstrate that they had a deeply trusting relationship during their period working together at the News of the World.

The existence of the relationship was discovered after police found a letter from Brooks to Coulson dated February 2004.

"What Mr Coulson knew, Mrs Brooks knew too and what Mrs Brooks knew, Mr Coulson knew too, that is the point. Because it's clear from that letter as at February 2004 they had been having an affair which had lasted at least six years. So that takes us right back to 1998 which is the whole conspiracy period," Edis told the jury.

Brooks edited the News of the World between 2000 and 2003, before moving on to edit the Sun. Coulson was her deputy at the Sunday newspaper, stepping up to become editor on her departure to the daily title.

Brooks married actor Ross Kemp in 2002, having been in a long term relationship with him for several years previously. They separated in 2006 and were divorced in 2009. She went on to marry Charlie Brooks, who is also on trial with Rebekah for conspiring to pervert the course of justice.

Coulson married his wife Eloise in 2000.

Charlie Brooks and Rebekah Brooks arrive at the Old Bailey. Photograph: Rex

Edis explained that the letter had been found on a computer when the Met police investigating the phone-hacking scandal in 2011 searched her home. "A computer was found in a cupboard in Mrs Brooks's London address and it was examined. On it was found a Word document written by her to Mr Coulson.

"It seems to be in February 2004 and it was written undoubtedly to Mr Coulson. Whether it was ever sent or received by him we do not know, because the evidence is the document on the computer," Edis told the jury.

The court heard that the letter – apparently written by Brooks in response to Coulson trying to end the affair – included a declaration of her love for her colleague.

Edis said the letter was "intelligent" and "well written" and appeared to have been written after Coulson "was seeking to break off the affair".

It was "perfectly obvious from the letter that this cause her a great deal of grief", Edis said.

The prosecutor added that he would only read out the last part of the letter and there was no way of knowing if it had been sent or received.

Brooks wrote: "Finally, the least of my worries, but how do we then work this new relationship? There are hundreds of things which have happened since Saturday that I would normally share with you."

She continued: "Most important, the fact is you are my best my 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. In fact, without our relationship in my life I'm really not sure I will cope."

Brooks went onto say: "The thought of finding out anything about you from someone else fills me with absolute dread."

Former News of the World editor Andy Coulson arrives at the Old Bailey on Friday. Photograph: Leon Neal/AFP/Getty Images

The jury heard that Brooks talked about how their new future relationship would work, asking if she should email "if anything important happens".

She added: "I don't understand this, we are either there for each other or we are not.

"How will this work for you? Do we limit contact until we absolutely have to?"

Edis told jurors he was not revealing the affair to deliberately intrude into their privacy or to make a "moral judgment," before giving his reasons for its disclosure.

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

Mr Edis had told the jury that the letter contained a "revelation" that needed to be put to the jury as an important part of the prosecution's evidence. He introduced the sensitive matter by saying: "I want to tell you about something that I want to handle as carefully as I can."