Two weeks ago, German intelligence agents noticed an unusual user in a chat room known as a digital hideout for Islamic militants. The man claimed to be one of them — and said he was a German spy. He was offering to help Islamists infiltrate his agency’s defenses to stage a strike.

Agents lured him into a private chat, and he gave away so many details about the spy agency — and his own directives within it to thwart Islamists — that they quickly identified him, arresting the 51-year-old the next day. Only then would the extent of his double life become clear.

The German citizen of Spanish descent confessed to secretly converting to Islam in 2014. From there, his story took a stranger turn. Officials ran a check on the online alias he assumed in radical chat rooms. The married father of four had used it before — as recently as 2011 — as his stage name for acting in gay pornographic films.

Authorities on Tuesday said they had arrested him on suspicion of preparing to commit a violent act and for violating state secrecy laws. His arrest was first reported in Germany’s Der Spiegel. But two German officials familiar with the case — a senior intelligence official and a senior law enforcement official — revealed new details about his double life in interviews with the Washington Post. They include his role in pornographic films, which could cast a fresh light on the judgment and vetting of the German intelligence agency at a critical time.