Gothenburg disctrict court on Wednesday sentenced the 16-year-old to four years in a detention centre for juvenile offenders and to pay damages to the relatives of the victim.
After he has served his time the boy, who is understood to be of north African origin and had been sleeping rough in the streets of Sweden, will be deported from the Nordic country, said the court.
The gruesome killing took place in June, with a trial getting under way at the end of last year.
The boy, who court documents said broke down in tears during police interrogations, told the court it had been carried out in self-defence.
He claimed the man had approached him on the street, dressed as a red-haired woman, and offered him clothes, food and a place to shower. After they arrived at the apartment he said the man had tried to rape him.
However, police managed to recover a video from the boy's mobile, which showed him shouting and swearing at the man and insulting his sexuality. The victim was found by his partner with a shirt tied around his neck and a dead snake draped around his neck.
The boy's DNA was found at the scene and under the victim's finger nails. Another teenager, 19, who was also present in the apartment, was charged with protection of a criminal.
Medical X-ray analysis indicated that the boy was older than the 15 years he had claimed he was at the time of the murder, however the court found that it was “likely” that he was at least under 18.
It noted that if he had been an adult the sentence would have been sentence to life in prison.