North Carolina politicians have voted to roll back North Carolina's "bathroom bill" in a bid to end the backlash over transgender rights that has cost the state dearly in business projects, conventions and basketball tournaments.
The compromise plan, announced on Wednesday night by the state's Democratic governor and leaders of the Republican-controlled legislature, was worked out under mounting pressure from sports governing body NCAA, which threatened to take away more sporting events.
It was sent to Governor Roy Cooper for his signature.
Mr Cooper had urged politicians to support the deal, which among other things repeals a year-old law that said transgender people have to use the public bathrooms that correspond to the sex on their birth certificate.
The compromise was condemned by some on both sides, with conservatives staunchly defending the current law, also known as House Bill 2, and gay and transgender activists complaining that the new measure still denies them protection from discrimination.
They demanded nothing less than full repeal.
As a result, it was unclear whether the retreat from HB2 would quell the furore or satisfy the NCAA.
Republican Senator Dan Bishop, a primary sponsor of HB2, denounced the new deal on the Senate floor, where it was approved 32-16, with nine of 15 Democrats among the yes votes.
"This bill is at best a punt. At worst it is a betrayal of principle," the Charlotte-area legislator said.
The House passed the Bill 70-48 later in the day.
Republican Representative Scott Stone, who lives in Charlotte, urged his colleagues to vote for the Bill.
"We are impeding the growth in our revenue, in our ability to do more things for tourism, for teacher pay, while we have this stigma hanging over," Mr Stone said.
"The time has come for us to get out from under the national spotlight for negative things. You can't go anywhere on this planet without somebody knowing what is HB2 and having some perception about it."
While the new measure eliminates the rule on transgender bathroom use, it also says state legislators - not local government or school officials - are in charge of policy on public bathrooms.
House Bill 2 had also restricted local governments' ability to enact non-discrimination ordinances.
Under the Bill just approved, local governments cannot pass new non-discrimination protections for workplaces, hotels and restaurants until December 2020.
That moratorium, according to House Speaker Tim Moore and Senate leader Phil Berger, would allow time for pending federal litigation over transgender issues to play out.
"This is a significant compromise from all sides on an issue that has been discussed and discussed and discussed in North Carolina for a long period of time," Mr Berger said.
"It is something that I think satisfies some people, dissatisfied some people, but I think it's a good thing for North Carolina."
Gay rights activists criticised the proposal, saying it was not a true repeal.
"It doesn't matter if you are a Democrat or a Republican, if you vote for this bill, you are not a friend of the LGBT community," Equality North Carolina executive director Chris Sgro said.
"You are not standing on the right side of the moral arc of history or with the civil rights community."
The deal came as the NCAA said North Carolina would not be considered for championship events from 2018 to 2022 unless HB2 was changed.
The sports governing body said it would start making decisions on host cities this week and announce them in April.
North Carolina cities, schools and other groups have submitted more than 130 bids for such events.
The NCAA already pulled championship events from the state this year because of HB2.
HB2 also prompted businesses to halt expansions and entertainers and sports organisations to cancel or move events, including the NBA All-Star game in Charlotte and concerts by Bruce Springsteen and Pearl Jam.