MI5's headquarters on the Thames in London. Two spies, once lovers, are appearing in court over the end of their 'volatile' relationship. Photograph: Murdo Macleod

An MI5 spy sexually assaulted and beat his former girlfriend, a fellow spy, and refused to accept their relationship was over, a court heard. Mark Barton and the alleged victim met while working for the security services in 2009 and began a relationship in 2010. Southwark crown court heard that Barton – not his real name – and the woman had an "intense and passionate" relationship which was also "volatile".

Alison Morgan, prosecuting, said: "The allegations faced by the defendant arose because the defendant refused to accept the end of that relationship, and thereafter behaved in a manner that was obsessive, intimidating, violent at times and frightening towards his former partner, the complainant."

Barton, who appears in court under a pseudonym for security reasons, denies sexual assault, two counts of assault by beating, and putting a person in fear of violence by harassment. The complainant is referred to in court by her work "pin number" 2363.

Morgan said: "The prosecution's case is that from mid-August 2011 onwards, this defendant was unwilling to accept that his relationship with the complainant 2363, was over. He embarked on a campaign to win her back and to rekindle their relationship. "This campaign was persistent, disregarded her wishes and amounted to harassment.

"At times he behaved in an aggressive and entirely unwelcome fashion towards 2363, making her feel intimidated and fearful that he would use violence towards her … His behaviour escalated as time went on and he desperately tried to convince her to restart the relationship. This led to the use of sexual and physical violence towards her when she resisted his advances."

The barrister said the complainant told a number of people about what had happened and sought advice; that emails and texts existed showing the defendant's mindset; that warnings were given to Barton by his bosses and that people witnessed the incidents between them. The case continues.