RALEIGH, NC — A federal judge approved a legal settlement Tuesday affirming transgender people’s right to use restrooms matching their gender identity in many North Carolina public buildings.

The consent decree is expected to end a protracted lawsuit challenging North Carolina’s so-called bathroom bill and the law that replaced it.

The agreement between the plaintiffs and North Carolina’s Democratic Gov. Roy Cooper says that nothing in the current state law can be interpreted to “prevent transgender people from lawfully using public facilities in accordance with their gender identity” in buildings controlled by the state’s executive branch.

The agreement further says that executive branch officials, such as the current and future governors and their employees at state agencies are forbidden from using current state law “to bar, prohibit, block, deter, or impede any transgender individuals from using public facilities…in accordance with the transgender individual’s gender identity.”

In return, plaintiffs have agreed to drop pending legal action against the governor and other defendants.

North Carolina’s Republican legislative leaders, who passed the “bathroom bill” and its replacement, had opposed the agreement that’s been in the works since 2017.

The 2016 law, also known as H.B.2, required transgender people to use restrooms matching their birth certificates in state government buildings and other publicly owned structures including highway rest stops. While that requirement was later rescinded, a replacement law halts new local antidiscrimination ordinances until 2020. The transgender plaintiffs had continued to challenge the new law in court.

Joaquin Carcano, the lead plaintiff in the case, hailed the judge’s decision in a statement.

“After so many years of managing the anxiety of H.B.2 and fighting so hard, I am relieved that we finally have a court order to protect transgender people from being punished under these laws,” he said.

Still, he said that the current law’s moratorium on new anti-discrimination laws “remains devastating.”