In the last two years, an estimated 20,000 foreigners, about a quarter of them European, have joined jihadist groups in the Middle East, the majority of them filling the ranks of the Islamic State, Dr. Neumann said. Between 25 percent and 40 percent have already returned to Europe, he said. British officials estimate that more than 300 have returned.

Defectors have said that life under the Islamic State, also known as ISIS and ISIL, was far from the utopia they had been promised.

“ISIS wants to kill everyone who says no,” a 26-year-old Syrian fighter told NPR last year. “Everyone must be with them.” The defector said he had paid a smuggler to take him to Turkey, where he had to hide from Islamic State informants who prowled towns along the border. “I was thinking all the time, if they arrest me, if they stop me, they will behead me,” he said.

In another case, a Western fighter named Ibrahim said he had initially joined the group because he wanted to give humanitarian assistance to Syrians and to have a chance to live in a caliphate under strict Islamic law. But he eventually left, he told CBS. “A lot of people when they come, they have a lot of enthusiasm about what they’ve seen online or what they’ve seen on YouTube,” he said. “It’s not all military parades, or it’s not all victories.”

The fighter said he saw a couple being stoned to death for adultery, and considered that just, but he did not approve of aid workers, journalists and other noncombatants being beheaded.

“My main reason for leaving was that I felt that I wasn’t doing what I had initially come for and that’s to help in a humanitarian sense the people of Syria,” he said. “It had become something else — so, therefore, no longer justified me being away from my family.”

As disillusioned as a recruit might become, he or she must go to great lengths to leave the Islamic State, Dr. Neumann said. In one case, a fighter defected by fooling militants into thinking that he was luring his sister from Germany, even faking conversations on Facebook to show that his efforts were succeeding. He managed to flee to Turkey after telling the militants that he would pick her up on the border. “To get out of ISIS, you have to be quite shrewd,” Dr. Neumann said.

One of the first to recognize the value of such narratives was the United States’ Center for Strategic Counterterrorism Communications, Dr. Neumann said. One of its successes included a YouTube video released last year that “welcomed” recruits to the Islamic State by showing images of the group’s atrocities. The video has been seen 865,000 times. The unit also runs a similar campaign on Twitter under the handle @ThinkAgain_DOS.