Steven Watson appeared before Sheffield Crown Court on Tuesday, February 16, after admitting the offence, which took place in May of last year.
The court heard that the victim, who is a native of Somalia, had been walking through Barnsley town centre when he saw the 40-year-old and another man standing in the street.
Prosecuting, Stephen Littlewood told the court: “The victim was walking in Barnsley town centre and he reached Eldon Street when he saw two men. One of them was the defendant, who walked up to him and punched him in the face, breaking his glasses.
“He used his bike lock to try to defend himself and one of the members of the public who tried to intervene was black, and they were both referred to as n******.”
The court heard that the defendant had previous convictions for violence and affray and was on bail for another matter when he carried out the attack.
Defending, Vanessa Saxton, said that Watson - who is himself mixed race - of Farm Road, Barnsley, has a significant drink problem and couldn't remember committing the offence when he was later arrested.
She said: “He’s thoroughly ashamed of himself for using racially-motivated language. He is adamant that he doesn’t hold those views and doesn’t see himself as a racist, but he accepts that this offence is racially aggravated.”
Sentencing Watson to four months in prison, Recorder Kirtley told him: “You have described yourself as mixed race, and it beggars understanding why you did what you did.”