A German spy arrested after posting in a chat room for Islamist militants was also a gay porn actor, it has emerged.

The 51-year-old was a full-time employee of the German equivalent of MI5 when he allegedly started using extremist chat websites. Security sources said he was planning a bomb attack “in the name of Allah” on the intelligence agency’s headquarters in Cologne until he was discovered by an informer.

The family man's role in pornographic films was uncovered when agents ran a check on his chat alias following his arrest, and found it had also been his stage name as recently as 2011, the Washington Post reported.

Bild reported that copies of the films turned up during a search of his apartment.

The worker, a German citizen of Spanish descent and a married father of four, was caught out when suspicious agents began chatting to him privately having seen his offers to help Islamists infiltrate the organisation.

He gave away so many details of his work that they were able to arrest him the next day.

He confessed to having converted secretly to Islam in 2014 and was arrested on suspicion of preparing to commit a violent act and for violating state secrecy laws.

Hans-Christian Ströbele, a member of the German Parliament's intelligence oversight committee, told the Post: "It's not only a rather bizarre, but also a quite scary, story that an agency, whose central role it is to engage in counter-espionage, hired an Islamist who potentially had access to classified information".

Officials at the agency, the Bundesamtes für Verfassungsschutz, said the man had undergone its vetting process before he was hired in April.

It was revealed in November that a teenage Isis supporter had scouted out some of Germany's most iconic buildings and monuments for a prospective attack.

The 19-year-old Syrian man was arrested in March for suspected links to Isis after the alleged plans were uncovered.