BERLIN — A German court sentenced a 20-year-old man who traveled to Syria to fight alongside a group associated with the Islamic State to three years and nine months in juvenile detention, the country’s first conviction of a returned jihadist.

The Frankfurt court ruled on Friday to sentence the man, identified only as Kreshnik B. because he was tried as a juvenile, to a term focused on rehabilitation after he confessed to willingly quitting the militant group, also known by the acronyms ISIS or ISIL, to return home. German law allows young adults to be tried as juveniles if they are deemed to lack the maturity of an adult.

Kreshnik B. had told the court that while in Syria, he grew bored and frustrated that he and other Europeans with no prior military training were given limited responsibilities and sidelined from major battles.

Security officials estimate that about 3,000 Western Europeans have left their home countries to join the fight in Syria. Fears are growing over the potential threat that they could pose to society upon their return.