Two Democratic lawmakers from Massachusetts want to end a controversial legal defense in which a criminal defendant claims violence against LGBTQ people was justified because of “panic” about the victim’s sexual identity or orientation.

The defenses “characterize sexual orientation and gender identity as objectively reasonable excuses for loss of self-control, and thereby illegitimately mitigate the responsibility of a perpetrator for harm done to LGBT individuals,” the bill says.

The controversial defense has become rarer as LGBTQ rights and protections have advanced, and has been banned in state courts in California and Illinois. Federal courts, however, still allow defendants to assert the claim.

The new legislation argues that such defenses seek to “completely excuse crimes such as murder and assault on the grounds that the sexual orientation or gender identity of the victim is provocation enough for the violent reaction of the defendant.”

“Murdering or assaulting anyone because of their sexual orientation or gender identity is not a defense, it is a hate crime,” Kennedy told HuffPost in a statement.

He added that “legal loopholes written into our laws that seek to justify violent attacks against our gay, lesbian, bisexual and transgender neighbors should never have existed in the first place.”

Murdering or assaulting anyone because of their sexual orientation or gender identity is not a defense, it is a hate crime.Rep. Joe Kennedy (D-Mass.)

“Sexual orientation or gender identity cannot ever excuse violence, and our courtrooms should not be used as chambers of hate,” Markey told HuffPost in a statement. “Gay and trans panic legal defenses reflect an irrational fear and bigotry toward the LGBTQ community and corrode the legitimacy of federal prosecutions. These defenses must be prohibited to ensure that all Americans are treated with dignity and humanity in our justice system.”

Gay and trans panic defenses have appeared in court opinions in about half the states since the 1960s, according to the Williams Institute at UCLA’s School of Law. Defendants have used the concept to claim they were provoked, driven into a temporary state of mental instability, or needed to defend themselves, researchers found.

The killers of gay college student Matthew Shepard in Laramie, Wyoming, in 1998 famously tried to claim Shepard made a pass at them and they panicked. A Wyoming judge refused to allow the panic defense, and the two killers were eventually sentenced to life.

Advocates applauded the legislation.

“Historically we have seen panic defenses used as a Trojan horse to attempt to bring societal prejudices and hatred against LGBTQ people, and especially transgender women and gay men, into courtrooms in an effort to justify types of violence that are simply never justifiable,” Sue Yacka-Bible, communications director at GLAAD, told HuffPost. “Explicitly banning this practice will go a long way in protecting survivors and the friends and family of victims as they engage with the criminal legal system at a deeply painful period of their lives.”

D’Arcy Kemnitz, executive director of the National LGBT Bar Association, said in a statement last week that such “panic” defenses “have long stood as a symbol of dangerous and outdated thinking.”

“An individual’s sexual orientation or gender identity/expression should never justify a violent attack or murder,” Kemnitz said. “To say otherwise sends a message to the LGBT community that their lives are inherently less valued. The continued allowance of these defenses is a failure of the justice system.”