This was the first trial held in Germany of a jihadi raised in the country and accused of joining the radical militant group.
The court decided to treat Kreshnik B, who was born to Kosovan parents in Germany and spent over six months last year in Syria, as a juvenile due to a lack of maturity.
The judges said no evidence existed linking the defendant to direct fighting.
Judge Thomas Sagebiel said that as a youth the man could not resist the strong influence of his friends who were Islamic.
Although he displayed radical Islamist attitudes, the judge said he hoped a sentence as a minor would have sufficient educational effect on the young man.
In Germany, people who are 18 to 21 years of age can be considered juveniles under the law if they have been judged to lack the sense of responsibility of an adult.
The sentence for the man was six months less than prosecutors had requested but more than the 39 months the defense lawyer asked for.
This sentence came after the defendant in exchange for a lenient sentence by the judges, admitted to joining the Islamic State and receiving training in the use of weapons.
The defendant appeared relaxed upon entering the courtroom and looked down when his verdict was read.
He was casually dressed and sported a beard.
Militants from Islamic State have captured huge swathes of land in Iraq and Syria, executed Western prisoners, killed a number of Muslims who are non-Sunni and declared their own caliphate ruled by sharia law.
Thousands of volunteers from the West have gone to Iraq and Syria to join the militant group, which has raised fears in the United States and Europe of these people returning and carrying out domestic attacks.
It is estimated that over 550 citizens from Germany are members of the Islamic State in Syria and Iraq and close to 60 have died in fighting, with some carrying out suicide bombings, said authorities.
About 180 are thought to have returned to Germany, while another 300 are under investigation.