South Carolina education officials have agreed not to enforce part of their own state law that bans sex education teachers from mentioning any relationships other than heterosexual ones — unless the talk involves sexually transmitted diseases.

Civil rights groups last month sued the state, saying the law violated the U.S. Constitution. They also say it led to a hostile classroom climate that fostered bullying of students who are not heterosexual.

A federal judge on Wednesday signed a consent agreement reached between the plaintiffs and the state, in which both sides agree not to punish teachers who violate the law. State Superintendent of Education Molly Spearman now has 60 days to inform all of South Carolina’s public school superintendents of the deal, and the order that they must no longer follow the requirement.

The law states that any teacher who allows “a discussion of alternate sexual lifestyles” including “homosexual relationships except in the context of instruction concerning sexually transmitted diseases” can be fired.

In the agreement, South Carolina conceded that its law “is not rationally related to any legitimate state interest” and would fail any level of judicial review under the Equal Protection Clause. The judge also barred state officials from enforcing or applying the requirement on teachers.

State officials had no immediate comment Wednesday, but told the judge in court papers that the agreement forged Wednesday is in the public interest. The deal is fair and reasonable, given the strength of the plaintiffs’ case, both sides said in requesting the deal. The South Carolina Attorney General’s Office had earlier issued an opinion that a court would likely conclude the law violates the Constitution.

The consortium of civil rights groups who filed suit said that one-sided sex education classes stigmatize non-heterosexual students —- a group already at a heightened risk of suicide.

Their lawsuit recounted the experience of one student from Greenville. He was in middle school when a classmate threw a Clorox wipe at him and “told him that he was diseased and that the stairway to hell was ‘rainbow-colored.'” The classmate then kicked him in the chest.