Prosecutor Andrew Edis told jurors at the Old Bailey that in February 2004, when the pair were both working at the media giant, they had been having a relationship for some years.
He said a letter was found on Mrs Brooks's computer from February 2004, that made the relationship clear.
Mr Edis said: "The point that I'm going to make in relation to that letter is that over the relevant period, what Mr Coulson knew, Mrs Brooks knew too. And what Mrs Brooks knew, Mr Coulson knew too - that's the point.
"Because it is clear from that letter that, as of February 2004, they had been having an affair which had lasted at least six years."
Mr Edis told the court that the pair had been having an affair dating back to around 1998, spanning the period covered by their phone-hacking conspiracy charge.
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.
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.
Mr Edis described the letter, saying: "It appears that Mr Coulson was seeking to break off the affair... and this is Mrs Brooks' reaction to him telling her that and it is clearly obvious from the letter that it caused her a great deal of grief."
He said she wrote that there were things which had happened since Saturday night which she would normally have shared with Coulson, "some important, most trivial".
He said she wrote: "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.
"In fact without our relationship in my life I am not sure I will cope."
Brooks, 45, of Churchill, Oxfordshire; Coulson, also 45, from Charing in Kent; former NotW head of news Ian Edmondson, 44, from Raynes Park, south west London; and the tabloid's ex-managing editor Stuart Kuttner, 73, from Woodford Green, Essex, all deny conspiring with others to hack phones between October 3 2000 and August 9 2006. Private investigator Glenn Mulcaire has already admitted phone hacking.
Mr Edis went on to tell the jury that key evidence showed that Mulcaire, Brooks, Coulson and Kuttner had been involved in hacking the voicemail of murdered Milly Dowler.
It was the revelation that the Sunday paper had hacked the schoolgirl's phone which led to the closure of the NotW and the Leveson Inquiry into press standards.
The prosecutor said Milly's family had been through an "agony of hope" as they "yearned for their missing daughter" for months until her body was found in November 2002.
"The prosecution say that the NotW, through Mr Mulcaire, hacked her (Milly's) phone during that time," he said.
"We say that Mr Mulcaire did the hacking and Mrs Brooks, Mr Coulson and Mr Kuttner - not Mr Edmondson, he wasn't around at that time - were criminally involved in the conspiracy which resulted from that phone hacking."
Mr Edis said Brooks took a particular interest in the Milly Dowler story because of her previous involvement in a campaign surrounding another murdered schoolgirl, Sarah Payne.
Brooks remained with her head bowed and Coulson looked ahead towards the prosecutor as their affair was revealed to the jury.
The court heard that Brooks went on holiday to Dubai in April 2002, but remained in contact with Coulson while she was away.
Mr Edis said: "That's why you need to have the full context of their relationship - because while she was away she was in contact with him, we say.
"Of course, what I've told you may mean that they had all sorts of personal reasons for wanting to remain in contact with each other, but we say to you that it's clear from the timing of the contact that it was at least partly work-related."
The case continues.