A security guard at Worcester's Jobcentre was racially abused as he tried to escort a rowdy man from the building.
Nicholas Simpson complained that a member of staff had refused to give him £30 and began shouting that he would "break the place to pieces".
Guard Everton Archibald told Simpson to keep his views to himself and put a hand on his back.
But Simpson branded him "a useless moron" and made racist comments before warning that he would stab Mr Archibald when he saw him alone in the city, said David Swinnerton, prosecuting.
Granted bail, Simpson was seen three months later brandishing an 80-centimetre-long samurai sword in Westminster Road, Worcester. When police tried to arrest him, he broke free and vanished over a fence into a garden.
Simpson, aged 20, of Wakefield Close, Worcester, pleaded guilty to possession of an offensive weapon in public and escaping from lawful custody on the day he was due to face trial by jury.
He had already pleaded guilty to the earlier offence of provoking racially aggravated fear of violence.
Judge John Cavell said his "deeply unpleasant and potentially serious" crimes passed the threshold after which Simpson could be jailed.
But he accepted that Simpson's mental problems, outlined in a psychiatric report, caused diminished responsibility for his actions.
He sentenced him to six months detention, suspended for two years, with a two-year community order.
Worcester Crown Court heard that Simpson went into the Jobcentre in Sansome Street on March 2 last year with friends.
Ten minutes later he came downstairs shouting and swearing. As he left the building he spat at a traffic warden. He was arrested 10 days later.
Members of the public then called police on June 28 when they saw the defendant waving the sword about while laughing and joking, said Mr Swinnerton.
When a patrol car arrived, he threw the sword into a hedge but was recognised by two officers.
A police helicopter joined the search after he escaped. Simspon handed himself in seven hours later. He had previous convictions for battery and harassment.
Tom Challinor, defending, said mental illness lay at the root of his offending.
His comments to the guard resulted from an outburst of anger rather than from deep-seated racist views.
Mr Challinor said he had not intended to frighten anyone with the sword but was only larking about with friends.
The former forklift truck driver could no longer work due to illness but he had quit illicit drugs and was supported by his parents, who were at court.
Comments: Our rules
We want our comments to be a lively and valuable part of our community - a place where readers can debate and engage with the most important local issues. The ability to comment on our stories is a privilege, not a right, however, and that privilege may be withdrawn if it is abused or misused.
Please report any comments that break our rules.
Read the rules hereComments are closed on this article