(Reuters) - Transgender people in North Carolina can use any public restroom in state-run buildings that conforms with their gender identity under a U.S. court settlement approved on Tuesday, in the latest turn of a long-running dispute that divided the state.

FILE PHOTO: A bathroom sign welcomes both genders in Durham, North Carolina May 3, 2016. REUTERS/Jonathan Drake

The settlement, which overturns part of a state law, ends a three-year legal fight by transgender people in North Carolina seeking the right to use the bathroom of their gender identity.

A 2016 North Carolina law, known as House Bill 2, required transgender people in state-run buildings use the bathrooms, changing rooms and showers that corresponded to the sex on their birth certificates.

The American Civil Liberties Union represented transgender plaintiffs seeking to block the law in court, arguing it violated their rights to equal protection and privacy under the U.S. Constitution.

“While this part of the court fight may be ending, so much urgent work remains as long as people who are LGBTQ are denied basic protections from violence and discrimination simply because of who they are,” Irena Como, acting legal director of the ACLU of North Carolina, said in a statement.

Some businesses and sports leagues boycotted North Carolina after passage of the law, which they saw as discriminatory against the lesbian, gay, bisexual, and transgender (LGBT) community.

Lawmakers in some other states had proposed similar legislation that failed to advance.

U.S. District Judge Thomas Schroeder ruled in 2016 that the state’s university system must allow transgender students to use bathrooms matching their gender identity.

Democratic former President Barack Obama’s administration also challenged the law in court.

Facing pressure in the courts, the North Carolina legislature in 2017 replaced House Bill 2 with House Bill 142.

The bill stated that the state legislature had the power to regulate bathroom access, but the legislature did not take action at that time to define access.

The new law left transgender people in limbo, according to the ACLU, which amended its lawsuit to challenge the new law.

The ACLU and the group Lambda Legal later reached a settlement with North Carolina Governor Roy Cooper, a Democrat, the ACLU said in a statement. It went to Schroeder for final approval.

Schroeder, in an eight-page ruling on Tuesday, said the settlement bars state officials from using the legislation “to prevent transgender people from lawfully using public facilities in accordance with their gender identity.”

The Republican-controlled North Carolina General Assembly filed court papers opposing the settlement.

House Bill 142 continues to prohibit cities in North Carolina from creating their own ordinances protecting LGBT people from discrimination until December 2020, and that was not affected by the agreement, according to the ACLU.