Former News of the World editor Andy Coulson told the hacking trial his affair with Rebekah Brooks "was wrong and it shouldn't have happened".

Giving evidence, the 46-year-old said the affair started in 1998, but was not "continual" and there were long periods where they were just close friends.

The married father-of-three acknowledged the "pain" the on-off relationship caused, particularly to his wife Eloise.

The Old Bailey has previously heard that Brooks and Coulson had several "periods of intimacy" during their time working together.

Jurors have seen a draft letter Brooks wrote to Coulson declaring her love for him. But in her evidence, she said they "weren't meant to be".

Coulson followed Brooks as editor of the now-defunct Sunday tabloid between 2003 and 2007, and before that was appointed in 2000 as her deputy.

He told the court that the pair first got to know each other in 1996 then became colleagues in 1998 when Brooks was made deputy editor of The Sun.

Asked about their personal relationship, the former Downing Street spin doctor said: "There was an affair that started in 1998. It ended quite soon after but it did re-start, as the court has heard.

"What I want to say is that it was not by any means continual. There were very long periods - very long periods - where the relationship was what it should have been," saying they were just close friends and colleagues.

"But I don't want to minimise it or excuse it. It was wrong and it shouldn't have happened and I take my full share of responsibility for the pain it has caused other people, not least my wife."

Both Brooks and Coulson are accused of conspiring to hack phones and separate charges of conspiracy to commit misconduct in public office.

Coulson's lawyer Timothy Langdale QC questioned him on how the affair affected their working relationship.

Coulson agreed he would exchange confidences with Brooks in a way he would not normally do with an editor.

But he denied the suggestion that the closeness of their relationship involved him "breaching professional standards or rules".

Mr Langdale said: "In particular, it has been suggested as a result of the closeness of your relationship you would share sensitive or exclusive stories."

Coulson said: "No, that did not happen - with the caveat unless on very particular occasions there was a pre-determined deal when there was a share between the two papers." After the affair, he said they remained friends.

Earlier, Coulson told how he spent a weekend with David Cameron after he resigned as his media adviser amid controversy over what he knew about phone hacking while he was NotW editor.

But the witness said he had not spoken to the Prime Minister since that pre-arranged social occasion in spring 2011.

Coulson resigned as NotW editor in 2007, after the conviction of former royal editor Clive Goodman for hacking, and joined Mr Cameron's team, first in opposition and then in Downing Street after the 2010 general election.

He resigned his post as Mr Cameron's media adviser in January 2011 amid the controversy over phone hacking, and was arrested later that year, then charged in 2012.

Coulson today said he had had "sparing" contact with former boss Rupert Murdoch since his resignation.

And of his contact with Mr Cameron, he said: "My family and I spent a weekend with him in the spring after I left. I have not spoken to him since."

He added that the invitation came before he left his Downing Street job.

Coulson described an atmosphere of intrigue and secrecy at the NotW when he joined the paper from the Sun as deputy editor under Brooks in 2000, saying it had become "destructive".

Mr Langdale went on to ask about Glenn Mulcaire's £105,000 annual contract in 2005, listed under his company Nine Consultancy for "special inquiries".

Coulson said at the time he had heard of the company in relation to a budget document. But he denied knowing about private detective Mulcaire, saying: "I did not know the name Glenn Mulcaire until he was arrested with Clive Goodman."

Asked if he ever inquired what Nine Consultancy did, he said: "I assumed the description special inquiries meant finding people, looking for people, possibly surveillance in the main and that Nine Consultancy was part of that process."

He told the court: "It was not an area of the News of the World I was particularly interested in.

"For me, finding people in newspapers is an incredibly important part of the process. You have got to get there first. I always viewed that as a central function of special inquiries."

Asked about the figure paid to Mulcaire's company, Coulson said: "I would not suggest that £100,000 is not a lot of money but in the context of a £32 million budget it's not a massive sum.

"The NotW spent a lot of money, we had a lot of money to spend on stories and a lot of things.

"I don't want to be dismissive of £105,000, but the reality is it wasn't a lot of money in the business I was running. We paid double that, I think, to the astrologer.

"There were large sums of money being paid to people by the NotW."

Coulson, of Charing, Kent, is charged with conspiring to hack phones with Brooks and Kuttner and conspiring with former royal editor Clive Goodman to commit misconduct in a public office. All seven defendants deny charges against them.