For the first time in Colombia, the murder of a transgender woman has been punished as a gender-based hate crime, three years after the passage of a law that imposes tough sentences for hate crimes against women.

The woman, Anyela Ramos Claros, was killed last year in the municipality of Garzón after being shot in the back by Davinson Stiven Erazo Sánchez, who months earlier had tried to attack her with a knife, according to court documents. She died of multiple gunshot wounds.

Ms. Claros owned a hair salon where he was a client, the documents said. After being apprehended by the authorities, Mr. Sánchez tried to justify his actions by citing Ms. Claros’s sexual orientation, according to prosecutors in Garzón, which is about 100 miles southeast of Cali.

On Dec. 3, Mr. Sánchez was sentenced to 20 years in a psychiatric facility for aggravated feminicide — the killing of a woman because of her gender — and for a weapons charge.