A teenager made repeated attempts to slash a heroic passer-by with knife after he intervened in a street robbery in Leeds.
A judge described how it was a 'miracle' that bystander Ismael Moalim did not suffer serious stab injuries and praised him for his bravery.
Leeds Crown Court heard the incident happened on Cherry Row, Lincoln Green, on February 24 this year.
Andrew Shaw, prosecuting, said Mr Moalim stopped his car as he drove home from a mosque after spotting what he suspected was a knife-point robbery taking place.
He approached a youth in the street who told him he had just been robbed. Mr Moalim then told the youngster to get into his car.
They drove off before Mr Moalim stopped the vehicle and approached a group to ask them about the robbery.
A 16-year-old male, who cannot be identified, took out a knife from his waistband.
The prosecutor said Mr Moalim told the youngster he was committing a crime and could be arrested.
The defendant then said "I don't care" before lunging at him with the weapon.
It made contact with his jacket as the man tried to get out of the way.
The teenager then swung the weapon at the man's neck.
The blade cut through the material of his jacket and T-shirt but did not make contact with his body.
The group ran off but were followed by Mr Moalim and the teenager was arrested nearby.
He pleaded guilty to attempting to cause grievous bodily harm.
The court heard the defendant had been released from custody on licence for an offence of robbery, carried out in February 2016, when a woman was targeted in her own home.
Richard Reed, mitigating, said the youth accepted he would be facing a further period in custody for the offence.
Mr Reed said the defendant had been a "model prisoner" while in custody and was motivated to address his offending behaviour.
He was given a sentence of 43 months detention.
Judge Neil Clark said: "Here was a man acting properly, trying to act as a decent citizen and prevent someone committing crime and he was threatened and attacked by you.
"You struck out at him with a knife when he offered you no threat. The situation you created was exceptionally dangerous.
"How that man was not seriously injured is quite frankly a miracle.
The judge said Mr Moalim should be commended for actions.
He added: "It was exceptionally brave."