Prosecutor Alison Morgan KC told jurors that the attack at a London school was attempted murder 'as an act of terrorism'.
The defendant cannot be named for legal reasons.
Morgan said the boy was armed with a knife and insect repellent spray as he walked through school corridors. He stopped at a classroom where a lesson was taking place and repeatedly knocked on the door. When a child answered, the defendant sprayed that child in the face and entered the room, the court was told.
He was allegedly looking for a boy he knew and demanded: 'Where you at fam?' Morgan said he found the boy and stood behind him, grabbing at him and then stabbing him repeatedly. The boy was stabbed in the head, neck and once in the shoulder area.
The defendant then swore and twice exclaimed 'Allahu Akbar' ('God is the Greatest'), the court was told. As children screamed, the defendant allegedly watched the panic he had created and said: 'You wanna die fam. Come here!' He shouted 'Allahu Akbar' again and moved towards the terrified children, who raced to get away from him, Morgan said.
'Still armed with the knife, he left the classroom, went along the corridor and down the stairs,' Morgan told jurors. 'At the bottom of the stairs, he could see out into a playground area where other children were playing at break time. He went through the open door and approached a child he did not even know. He grabbed the child to the neck with his left arm, turned the child's head to expose his neck and then he stabbed the child in the neck, before walking back into the school building.'
Morgan said: 'Miraculously, notwithstanding that both children had been stabbed in the neck by the defendant, they both lived.'
The incident was captured on video taken on the defendant's mobile phone which was fixed facing outwards to record events, jurors were told. Much of what was known about the attack came from that footage, the court heard.
Morgan told jurors that the prosecution invites them to conclude that the defendant recorded the video in order to show others that he had committed a terrorist attack in the name of Allah.
The defendant deleted a number of applications from his phone after the attack but some fragments had been recovered, including an image created on 11 December 2025 of a so-called Islamic State flag, jurors heard.
The trial continues.