The group had been abusing staff at Marsh Way House, a homeless shelter in Wakefield, when Dean Cunningham became angry and ran after them with a kitchen knife shouting: "Come on then!"
Leeds Crown Court heard police were called and Cunningham was arrested after the incident on the afternoon of July 7 this year.
Robert Galley, prosecuting, said it was third time he was caught possessing a knife in public so custody was mandatory.
Lamborghini pictured with car on top of its bonnet at busy Leeds junction following crash
Rage Against The Machine pull out of headline slot at Leeds Festival
Leeds Bradford Airport: Full statement on August security staff strike
Teenager arrested in Leeds as part of firearms offences probe
Crack-addicted shop robber claimed pal borrowed his clothing
Cunningham appeared in court in June for possessing a knife and was given a six-month suspended sentence.
He has 92 previous convictions.
Appearing via video link from HMP Leeds, he pleaded guilty to possessing a knife in public and affray.
Christopher Styles, mitigating, told the court that the youths had been abusive to staff and were causing trouble that day.
Mr Styles said: "It was a misguided and unacceptable attempt to move those individuals away from the residential unit."
He said that Cunningham, who is now 47, had a very difficult upbringing in care.
Mr Styles said his client developed an addiction to cannabis, solvents and alcohol, then later heroin and spice.
Mr Styles said: "While it can't excuse his behaviour it provides some explanation to the position he finds himself in.
"He was homeless and addicted to spice. He has a long history of mental health difficulties."
But he said his time held on remand has helped him deal with his problems.
Judge Mushtaq Khokhar jailed Cunningham for 18 months.
He said: "Your time in custody so far has worked to your benefit.
"Your liberty may be restricted but while in custody your mental health has improved.
"You are medicated and are receiving counselling, you coming out would disrupt that, so the sentence is tailored for that."