A teenage boy who stabbed his teacher in class and then went on Facebook to boast about having “put a knife in his tummy” has been given an extended sentence of 11 years – but could serve less than three.

The boy, described as a low-achieving cannabis user with a criminal record, was 14 when he stabbed Vincent Uzomah, 50, a supply teacher, at Dixon Kings academy in Bradford on 11 June following an argument about an iPhone.

Bradford crown court heard that the attack was premeditated and partially racially motivated. Uzomah is black and the boy, who is of Pakistani origin, regularly referred to him “by the epithet beginning with the letter N”, the prosecuting barrister Jonathan Sharp said. The boy used the term just before plunging his knife into the teacher’s stomach, penetrating the delicate membrane enclosing Uzomah’s bowel.

Uzomah survived but in a statement read to court said the attack had left psychological scars. He said he wasn’t sure when if ever he would feel ready to return to the profession he loved. A committed Christian, he said he was praying to God that the boy “would realise that violence is no path to take and that He would help him rather to become a useful member of society”.

In the public gallery, the boy’s father, wearing a white tunic and crocheted skull cap, listened with his head bowed, while another relative fingered a string of prayer beads. The stocky defendant sat in the dock flanked by two security guards, occasionally yawning during the two-hour hearing.

Outside court, Uzomah said he forgave the boy, who cannot be named for legal reasons. “As a Christian I have forgiven this boy who has inflicted this trauma and pain on me and my family,” he said.

Sentencing the boy on Monday, the judge, Jonathan Durham Hall QC, called the boy a “dangerous young offender” and an “antisocial bully” who hated being disciplined by a black man. “You would not tolerate being told off by this gentleman of this background,” he told the boy.

Facebook Twitter Pinterest Police outside Dixons Kings Academy in Bradford after teacher Vincent Uzomah was stabbed last year. Photograph: Lynne Cameron/PA

He said it was an “appalling reflection on a small microcosm … of society” that within minutes or hours after the attack, the boy’s boastful Facebook post had garnered 69 likes. “How sick,” said the judge.

The boy had written: “The motherfucker getin funny so I stick the blade straight in his tummy.”

Facebook Twitter Pinterest Jonathan Sharp, from the Crown Prosecution Service, says it is ‘shocking’ that the pupil who stabbed his teacher in a partially racially motivated attack boasted about it on Facebook and received 69 ‘likes’

The judge rejected claims the boy made to a psychiatrist that “voices” told him to do it, and that he chanced upon the knife on the way to school. He said two of the boy’s classmates had heard him claiming he was going to stab a teacher.

The court heard that the boy was a “low achiever and of low academic ability” with a history of truancy. His fellow pupils described him as disruptive and a bully, though the academy’s deputy head said that until the attack “you could always relate to [the boy] and calm him down, and he would acknowledge his faults”.

Yet the boy stabbed Uzomah simply after the teacher ordered him to surrender a gold iPhone he had taken from his brother that morning. After muttering the words “bastard” and “nigger”, the boy went to the classroom door, saying “you can have my phone”, before taking out his knife and stabbing Uzomah in the stomach before running away and scaling the school fence.

After posting on Facebook, the boy whiled away the rest of the day on the streets of Bradford. He was arrested by the fountains in City Square with two other teenage boys, and on arrest said: “You got me.”

Despite his 11-year extended sentence, the boy could be out in the community within three years after Hall ruled that the “determinative” custodial part of his sentence be just six years. That means he will be released on parole after serving half of that, if he behaves.

This was one ground given for refusing an application by the Sun to be allowed to identify the boy. The tabloid had already named and photographed him the day after the attack, exploiting a legal loophole that allows minors to be named before they appear in youth court.

Refusing the application to drop reporting restrictions – which only apply until the boy is 18 – the judge said the “logistics” of the sentence meant the boy would probably still be under 18 when he was released into the community, albeit under tight supervision.

The boy’s welfare and rehabilitation had to come before the considerable public interest in naming and shaming him, said the judge.

The court heard that the boy was on bail for a burglary at the time of the attack. He had been arrested on 3 April in a house onin Bradford with another three boys. In March 2014 he had been given a six-month referral order for attempted robbery and common assault. When just 13 he and a friend had mugged two boys and threatened to kill them.

The boy was originally charged with attempted murder, but the Crown Prosecution Service agreed to drop that charge when he pleaded guilty to grievous bodily harm with intent.