A Utah man accused of yelling racial slurs at the young son of a black man and then shocking the father with a stun cane has been sentenced to nine months behind bars — an outcome called disheartening by a civil rights leader.

Defendant Mark O. Porter, 59, unleashed a diatribe describing African-Americans as "pimps" and "drug dealers" during his sentencing hearing Thursday, the Deseret News reported .

Porter will get credit for jail time already served and could be released as early as next month. He was also sentenced to a year of probation.

U.S. District Judge Dee Benson said Porter is a racist and condemned the courtroom speech as despicable but said he had to impose a sentence warranted by the confrontation that led to the charge.

"He's entitled to have those views. It's not against the law to be a racist," Benson said. "It is against the law to act on those racist views."

Utah NAACP Chapter President Jeanetta Williams said the punishment doesn't send a strong enough message that hate crimes won't be tolerated.

Prosecutors had asked for nearly four years in prison after Porter was convicted of a civil-rights housing violation that authorities called a hate crime.

"His ranting will continue on," she said. "I think that we have to be more careful about what people say and how they say it, and words do hurt."

Williams attended the hearing and said Porter's offensive comments in the courtroom showed he wasn't remorseful or apologetic.

Porter's speech touched on the sexual assault case against Bill Cosby and his own sister's marriage to a black man in the 1970s, among other things.

"I've been around a lot of blacks. I just don't want to associate with them anymore," Porter told the judge.

Prosecutors said he told the father and son to get out of the apartment complex during the 2016 confrontation. He previously told apartment complex employees he did not want to live near any blacks and told another neighbor that he thought blacks needed to be "exterminated," according to trial testimony.

Porter has since moved from the Salt Lake City suburb of Draper to Arizona.

Rose Gibson, a lawyer with the civil rights division of the Department of Justice, argued his use of the stun cane, which has an electrified metal bars, amounted to aggravated assault.

"The incident was serious for the family. It was serious for the community," she said.