Only days after a mass shooting at a gay nightclub in Florida, the judge in a hate-crime murder case in New York invoked the massacre on Tuesday as he sentenced a man to 40 years to life in prison.

The defendant, Elliot Morales, 36, was convicted in March of murder as a hate crime for killing Mark Carson, a gay black man, in the West Village in Manhattan three years ago, after spewing homophobic invectives at the victim and his companion.

“I can’t help but perceive or observe the parallel tragedy in Orlando,” the judge, A. Kirke Bartley Jr., said as he imposed the sentence in State Supreme Court in Manhattan. “That parallel is revealed in hatred, self-loathing, fear and death.”

Mr. Morales was convicted after a two-week trial during which he represented himself, assuming the dual roles of defendant and defense lawyer. Addressing Mr. Morales, Justice Bartley said the defendant’s ability to appear “calm, intelligent, well prepared, well behaved” could not deter from the fact that he also seemed to be “something worthy of a character in a Stephen King novel — in short a monster.”