In January 2017, Hassan had an urgent problem. He opened an encrypted messaging app and told an ISIS official in Syria he needed to speak with him about “a matter of life and death.”

Hassan had received an audio recording from a translator in Turkey who had recorded a meeting between Syrian militia fighters and a Turkish official preparing for Turkey’s upcoming assault on the ISIS-held city of al-Bab, Syria. Hassan passed the recording along to his ISIS contacts with a warning.

“Brother, it’s just bad stuff. It’s happening right now. That’s about the city of al-Bab. It’s just bunch of spies, bunch of stuff going on. And we just found out something today, last night, today. And I got to tell it too. I got to tell you guys about it,” Hassan said.

According to the recording, Turkey had learned the location of underground tunnels ISIS had built to move fighters and equipment while avoiding airstrikes from the U.S.-led anti-ISIS coalition. Turkish-led ground forces, Hassan wrote, were planning to use their knowledge of the ISIS tunnel network to prevent fighters from using them to flee the city once their assault began.

To accentuate the threat, Hassan sent a satellite photo with a red crosshair over a mosque in al-Bab where ISIS stored ammunition and explained that he thought Turkish forces would target it soon.

To Hassan’s shock, he would later learn that the ISIS contacts he’d reached out to were undercover FBI sources posing as terrorists. The FBI often uses such informants in terrorism cases, a fact Hassan knew all too well—because he was one of them.

Today, Hassan is sitting in prison contemplating the prospect of deportation from the United States. Hassan hid his conversations with the “ISIS” member from the FBI in a subsequent meeting with his handlers, pleaded guilty to a charge of lying to federal agents, and earned a sentence of nearly five years in prison.

“Hassan” is not his real name. The Daily Beast is using a pseudonym to refer to him and has chosen not to publish his attorney’s name or his country of origin. Hassan’s attorneys have expressed concern for his safety should the U.S. government deport him to his home country in the Middle East.

Neither the Justice Department nor Hassan’s attorneys responded to The Daily Beast’s requests for comment.

“ The FBI couldn’t have an informant who was ‘taking matters into his own hands, deciding what he’s going to want to investigate, what he’s going to want to then disclose to the FBI.’ ”

The world in which FBI informants operate is murky, as Hassan’s case shows, and the line between the courtship of a terrorist that could prevent an attack or encourage one is sometimes blurry.

Hassan claimed his mistake was the former. Though he accepted responsibility for concealing his conversations with potential ISIS members, he claimed in court that the outreach was a misguided attempt to recruit an ISIS “big fish” source for the FBI using old or inaccurate information.

If the Justice Department believed Hassan was a potentially dangerous terrorist sympathizer, it hasn’t said so. In explaining the basis of the prosecution, a Justice Department attorney said the charges had come about because the FBI couldn’t have an informant who was “taking matters into his own hands, deciding what he’s going to want to investigate, what he’s going to want to then disclose to the FBI.”

Hassan came to the U.S. in the mid-2000s, started his own business, and by all accounts lived the version of the American Dream that brings many immigrants to the country. It’s unclear how he linked up with the FBI as a confidential human source, but his background working for a Middle Eastern intelligence service before he came to the U.S. made him an appealing candidate.

He started young. By his own account, Hassan stopped working for the Middle Eastern intelligence service at the age of 14 or 15. “I worked in five different countries in the Middle East,” Hassan said in a court hearing, trying to explain why he’d reached out to the fake ISIS officials without FBI authorization. “Basically you say and do everything just to gain information or to make contact with other people where you can use the contact to gain more information.”

“ He dressed the part. He certainly looks the part… he speaks the language. ”

There’s little information about what other work Hassan performed in his career as an informant. In court documents, his lawyer offered some clues about Hassan’s assistance to the FBI. “He dressed the part. He certainly looks the part… he speaks the language,” his attorney told a federal judge. “And he was able to travel around and go places and just listen to people, talk to people, and bring that information back to the FBI.”

Over time, working for the FBI began to strain Hassan’s life and eventually cost him his marriage. Hassan’s attorneys wrote that their client’s “long hours and dedication to helping the FBI” resulted in him “ignoring his wife and marriage working up to 16 hours a day for the government.”

As Turkish forces closed in on the ISIS-held city of al-Bab, Syria, in late 2016 and early 2017, Hassan said one of his Turkish contacts, a translator, reached out claiming to have a recording of a meeting between Turkish officials and Syrian militiamen. The translator passed along the recording of the meeting and offered to sell Hassan information. Hassan claimed that he ran the translator’s information past local contacts who knew al-Bab.

When his contacts told him the information was old and his source was trying to con him out of money, Hassan said he thought he could use it as bait to reel in senior ISIS officials. Prosecutors later disagreed with Hassan’s assessment of the translator’s information and called it “accurate” and potentially “very, very beneficial” to ISIS in Syria.

Hassan reached out to a man he believed was an “American fighter” with ISIS in Syria and told him he needed to speak with an Arabic-speaking Syrian ISIS fighter. The outreach wasn’t random. As a federal prosecutor later noted, Hassan “had been allowed to contact this individual sometime before as part of his work” but his FBI handlers hadn’t told him to get back in touch. The American ISIS fighter—an FBI informant posing as a foreign fighter—handed him off to a second informant posing as an ISIS member, and Hassan sent him the translator’s recording.

Hassan’s FBI handlers met with him shortly after the conversations and asked him specifically whether he’d spoken with any ISIS members he hadn’t mentioned or given information about the location of ISIS fighters to anyone else. Hassan said no but had a change of heart 90 minutes after the meeting. He phoned the FBI agents and said a source had given him old and inaccurate information about ISIS fighters in Syria. In a subsequent meeting with federal agents, Hassan again hid the extent of his contacts with the purported ISIS members and claimed he’d only passed along screenshots of the recordings.

His attorneys would later argue that Hassan had lied because he was overly ambitious in an attempt to recruit an ISIS “big fish” and thought the FBI would tell him the effort was “too dangerous.”

It had happened to him before. Sometime around 2012-13, Hassan claimed he had reached out to the administrator of a jihadi website with a message saying “I want to do something big to harm” the U.S. When the FBI found out about it, they chastised Hassan as “too extreme” in his pursuit of sources and said he needed to get FBI approval before any future pitches.

“ Back home, Hassan ‘couldn't even tell his only family that he was not part of this ISIS crowd, that he was working with the FBI,’ according to his attorney. ”

The Justice Department, normally happy to trumpet the conviction of suspects in terrorism cases, has never put out a press release about Hassan’s case. Hassan himself has been keen to avoid publicity as well. He requested a closed hearing during his guilty plea and a judge concurred, ruling that the “sensitive nature of the charge and some of the factual allegations in this case might cause that to be a prudent course to take.” The Daily Beast obtained the transcripts of the court proceedings last month while doing a review of terrorism-related prosecution cases in the United States.

In a sentencing hearing, Hassan’s attorney explained that his client is “very likely a walking dead man” if he gets deported to his home country in the Middle East. Back home, Hassan “couldn't even tell his only family that he was not part of this ISIS crowd, that he was working with the FBI,” according to his attorney.

The obscurity of Hassan’s case is hardly uncommon. In 2017 the FBI arrested approximately 110 people related to international terrorism, according to statistics obtained by The Washington Post. In a recent briefing with D.C.-based reporters, a senior FBI official stated that the majority were arrested for non-terrorism charges. Researchers from George Washington University’s Program on Extremism, which closely tracks international terrorism cases using court records and Justice Department press releases, have been able to identify 38 of the 110 cases the FBI reported.