Former News of the World editor Andy Coulson has begun giving evidence in the phone-hacking trial at the Old Bailey in London.
He is the last of the seven defendants to give evidence in the trial. All seven deny the charges.
Mr Coulson told the court that his affair with colleague Rebekah Brooks was "wrong" and "shouldn't have happened".
The 46-year-old said the couple had an affair that started in 1998, but was not "continual" and there were long periods where they were just close friends.
The Old Bailey has previously heard that Ms Brooks and Mr Coulson had several "periods of intimacy" during their time working together.
Mr Coulson followed Ms 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 when a friend of his had died, and then became professional colleagues in 1998 when Ms 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 restart, 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 Ms Brooks and Mr Coulson are accused of conspiring to hack phones and separate charges of conspiracy to commit misconduct in public office.
Mr Coulson's lawyer Timothy Langdale questioned him on how the affair affected their working relationship.
Mr Coulson agreed he would exchange confidences with Ms Brooks in a way he would not normally do with an editor.
But the married father-of-three 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."
Mr 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."
It also emerged today that Mr Coulson spent a weekend with British Prime Minister David Cameron after he resigned as his media adviser amid controversy over what he knew about phone-hacking while he was editor of the News of the World.
Mr Coulson said he had not spoken to Mr Cameron since that pre-arranged social occasion in spring 2011.
He resigned as News of the World editor in 2007, after the conviction of former royal editor Clive Goodman for hacking, and joined Mr Cameron's team.
He resigned his post as Mr Cameron's media adviser in January 2011 and was charged with conspiring to hack phones 18 months later.
Mr Langdale asked him about his contact with his former bosses, Rupert Murdoch and Mr Cameron, since the resignations.
Mr Coulson told the Old Bailey he had "sparing" contact with Mr Murdoch since 2007.