A former MI5 spy narrowly avoided being butchered by terrorists while following a group of Islamist extremists in London, it has emerged.

The spy, who goes by the pseudonym Tom Marcus, claims to have narrowly avoided being lured into a trap set by radical Islamists who wanted to kill the intelligence operative.

He describes the incident in a new book, Soldier Spy, in which he gives an account of his life as an agent for Britain’s domestic intelligence agency, MI5.

The book will be published this week, having already been vetted by MI5 to prevent security breaches.

Iran claims they've arrested spy working for British intelligence in country's economic sector ttp://on.rt.com/7msn pic.twitter.com/tM6ccNh0Te — RT UK (@RTUKnews) August 16, 2016

Marcus worked as a mobile surveillance officer with MI5 from 2005 to 2013 after a career in special operations with the army.

In his autobiography, Marcus claims a group of extremists used counter surveillance techniques to track who was following them and lure him into an alleyway.

His operation was quickly abandoned by MI5 controllers when they realized what was happening.

It was later discovered that the extremists had made preparations to film the murder of the spy. When the authorities searched their London flat, they found the floor had been covered with plastic sheeting, while the room also contained a black flag, three butchers’ knives, and a video camera.

Spy cops watching British Green Party figures despite Met Police pledge https://t.co/6Gqw0etqxmpic.twitter.com/tJmCLTWPb6 — RT UK (@RTUKnews) April 28, 2016

The biggest operation Marcus claims to have taken part in involved foiling a plot in 2009 in which al-Qaeda planned to blow up landmarks in Manchester over the Easter bank holiday.

He left the security services after being diagnosed with post-traumatic stress disorder (PTSD) and is having difficulty finding a job.

“The only really well-paid options for someone like me were in places like Iraq and Afghanistan, but I just couldn’t risk my life doing that,” Marcus told the BBC’s Victoria Derbyshire program.

Rebel MI5 spy fights to expose Guantanamo torture secrets https://t.co/V4WObAMo9Mpic.twitter.com/QwMRj3uxkC — RT UK (@RTUKnews) January 25, 2016

“It was never an option. I didn’t want my PTSD to come back. And no amount of money is worth risking being caught and beheaded.”

Since leaving the agency, he has had to take up jobs in fast food restaurants and call centers to get by.

“Working as an MI5 surveillance officer is seen as a job for life – so when you have to come out it’s very difficult to figure out what job you can do,” he said.

“You can’t answer the question about what you’ve been doing for the last 10 to 15 years in a job interview properly because you’d be breaking the Official Secrets Act.

“So, work-wise, I just started at the bottom of the pile again. I got an MI5 pension but I had to make money by working in call centers and flipping burgers to build up work experience.”