A New York City man who joined the Islamic State group in Syria before fleeing home and giving the FBI timely intelligence about terror threats was sentenced Thursday to 10 years of supervised release after U.S. authorities took the unusual step of seeking leniency in his case.

The Bangladeshi immigrant admitted going to Syria to support the Islamic State group but was credited for having a change of heart and helping the FBI. The judge also decided that all of the man's electronic communications will be monitored.

The defendant, identified only as "John Doe" out of fears of retribution, wept at a hearing Wednesday. He called himself "an idiot" for supporting the militant group he says quickly disillusioned him.

"I made the greatest mistake of my life," the 29-year-old man told U.S. District Judge Jack Weinstein. "I was stupid and lost, and found myself in deep danger."

Federal prosecutors in Brooklyn have sought lengthy sentences in several cases involving radicalized, would-be Islamic State recruits who were thwarted before they could either fight for the group overseas or plot an attack on U.S. soil. The man's case differs because he succeeded in joining IS for several months in 2014 and gaining access to inside information as the group was trying to establish a self-styled "caliphate" that posed a threat to the U.S. at home and abroad.

He began talking "within hours" of sneaking away from an IS camp in Syria, making him "uniquely situated to inform the government of (the group's) strategies, tactics, techniques, procedures, personnel and logistical operations," prosecutors said. Once back in the U.S., he secretly pleaded guilty to providing material support to a terrorist organization as part of a cooperation agreement.

Details of the man's odyssey had been officially kept under wraps until this week, when prosecutors unsealed court papers in advance of the sentencing.

The papers say the man had an uneventful upbringing in a Muslim household but grew despondent when his pregnant sister died from a sudden illness. He eventually became immersed in Islam and dropped out of college.

"I guess it was his way of mourning," his sister said in court without disclosing his name. "He was withdrawn. . We stopped speaking."

His online consumption of IS propaganda was flagged by the FBI, which warned him not to pursue a relationship with extremists, the papers say. Instead, he travelled to Turkey and, using social media for guidance, made his way into IS-controlled territory.

"He disappeared one morning and we had no idea where he went," the sister said.

Soon he was "confronted with the brutality of the organization and its dubious religious pronouncements, which were not consistent with the defendant's understanding of his faith," court papers say.

The man avoided battle duty by convincing his recruiters he had technical skills that "he had only seen in movies," the papers say. So he instead was given logistical and support roles until he secretly sent a message to the FBI offering his help, then risked crossing the Syrian border with IS documents.

"If he had been discovered, he would have been summarily executed," his attorney, Gary Villanueva said in court.

Along with his cooperation, authorities have credited the man with participating in a private intervention "with a young man who was being led astray" by IS propaganda. He also helped in the development of a community terrorism prevention program, they say.

On Wednesday, he told the judge he had earned a finance degree from a public university while under protective custody. At the same time he's "keeping a low profile for the safety of myself and my family," he said.

He's thankful, he said, for the chance "to work against the most brutal organization on earth."