Sen. Edward Markey and Rep. Joe Kennedy, both Massachusetts Democrats, are pushing legislation that would end the use of so-called “gay panic” and “trans panic” defenses in federal court.

The legislation, titled Gay and Trans Panic Defense Prohibition Act of 2018, states that these controversial defenses “seek to partially or 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.”

This rare defense tactic is already banned in California and Illinois but is still theoretically usable in federal court. With this bill, Markey and Kennedy aim to change that.

“Gay and trans panic legal defenses reflect an irrational fear and bigotry toward the LGBTQ community and corrode the legitimacy of federal prosecutions,” Sen. Markey said in a statement. “These defenses must be prohibited to ensure that all Americans are treated with dignity and humanity in our justice system.”

FILE PHOTO: Rep. Joe Kennedy III, D-Mass., speaks to supporters outside the U.S. Capitol on June 23, 2016. Pete Marovich / Getty Images

Rep. Kennedy said “murdering or assaulting anyone because of their sexual orientation or gender identity is not a defense, it is a hate crime.”

“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,” he continued in a statement shared with NBC News.

According to a 2016 report by the Williams Institute at UCLA Law, “the gay and trans panic defenses have appeared in court opinions in approximately one-half of the states” since the 1960s.

“No state recognizes gay and trans panic defenses as freestanding defenses under their respective penal codes,” the Williams Institute report explains. “Rather, defendants have used concepts of gay and trans panic ... in order to reduce a murder charge to manslaughter or to justifiable homicide.”

One of the most notorious examples of the so-called gay panic defense was nearly 20 years ago during the Matthew Shepard murder trial. Shepard, a 21-year-old gay college student, was violently beaten, tied to a fence and left for dead outside Laramie, Wyoming. He succumbed to his injuries in the hospital on October 12, 1998.

Russell Henderson, left, and Aaron McKinney appear in Albany County court in Laramie, Wyoming, on Oct. 9, 1998, during their trial for the death of Matthew Shepard. Ed Andrieski / AP

During their trial, Russell Henderson and Aaron McKinney claimed that Shepard had made a pass at them and caused them to violently panic. In this instance, their defense failed, and they were both sentenced to life in prison.

With the Gay and Trans Panic Defense Prohibition Act of 2018, Congress is taking a step the legal community has been urging for years.

Back in 2013, for example, the American Bar Association passed a resolution that called on lawmakers to “take legislative action to curtail the availability and effectiveness of the ‘gay panic’ and ‘trans panic’ defenses.”

In addition to Markey and Kennedy, the bill has 10 cosponsors in the House and five in the Senate, including Sen. Tammy Baldwin, D-Wisconsin, the upper house’s only LGBTQ member.

FOLLOW NBC OUT ON TWITTER, FACEBOOK AND INSTAGRAM