Euan Craig, 14, suffered serious head injuries when he was punched repeatedly at Rosshall Academy in Crookston, Glasgow, on May 23. He died the next day in hospital.
The teenager responsible, who cannot be named for legal reasons, landed the blows after being hit accidentally by a sponge ball.
The accused, who is now 15, admitted a charge of culpable homicide at an earlier court hearing.
Sitting at the High Court in Edinburgh yesterday, judge Lord Bracadale ordered the killer be detained for three years and six months.
Passing sentence, the judge told the court: "The assault was a wholly unnecessary one."
He added: "By all accounts, he [Euan] was a popular and well-rounded boy
"He had his whole life ahead of him. His prospects were good and he had every expectation of going on to leave school, enter higher education and graduate to a worthwhile career. He came from a close-knit family and was plainly the apple of the eye of his father and mother. He was close to his sister.
"It is clear his untimely death has had a profound effect on the family, who are going to have to live with this immeasurable loss."
The court heard previously that Euan and the teenager, who was 14 at the time of the attack, were third-year pupils who knew one another but were not friends.
Euan and his friends were playing with a sponge ball while they waited for their class to begin when Euan mistakenly hit the attacker on the side of his face.
Euan apologised but the teenager launched an attack, hitting him around five times on the left side of his head, despite the victim's repeated apologies.
The accused eventually stopped and walked out of the gym hall. Moments later Euan slumped to the floor and appeared to suffer a seizure. He was taken to Glasgow's Southern General Hospital but was pronounced dead the following day. The cause of death was recorded as head injury.
Defence QC Ian Duguid told the court that placing the teenager in secure care "may impact negatively on him in the longer term".
He also said of the events: "These are consequences which are extraordinary from an event which might have passed off as just another school fight."
However, Lord Bracadale said the "sustained nature of the assault, the circumstances in which it was committed and the devastating consequences which followed from it" meant the only appropriate sentence was a custodial term.