Image copyright Reuters Image caption Forcing transgender people into specific bathrooms was the best-known effect of HB2

North Carolina lawmakers have approved the repeal of a controversial law that limits protections for lesbian, gay, bisexual and transgender (LGBT) people.

A key element banned transgender people from using toilets in accordance with their chosen gender, earning the measure the "bathroom law" tag.

The state House of Representatives and the Senate cleared the repeal bill after reaching a late-night deal.

The deal came hours before the state was to lose key basketball fixtures.

Democratic Governor Roy Cooper has signed the measure into law.

The deal was announced late on Wednesday by Mr Cooper and Republican state lawmakers.

Mr Cooper, who ran for office on a platform of repealing the measure, known as House Bill 2, said: "It's not a perfect deal, but it repeals HB2 and begins to repair our reputation."

Majority Republican leaders Tim Moore and Phil Berger said in a joint statement: "Compromise requires give and take from all sides, and we are pleased this proposal fully protects bathroom safety and privacy."

But the terms of the deal have angered LGBT activists and some of the state's most conservative lawmakers.

'Train wreck'

The law had required transgender people to use toilets in schools and government buildings that correspond to the sex listed on their birth certificates.

Although the deal repeals the law, state legislators will remain in charge of policy on multi-occupancy restrooms.

Image copyright AP Image caption State Congress Republicans Moore (L) and Berger said the deal was a compromise

It creates a moratorium so that local government, state colleges and universities cannot pass measures extending non-discrimination on sexual orientation and gender identity until December 2020.

The compromise angered LGBT activists.

Equality NC executive director Chris Sgro said before the proposal was agreed that it was "a train wreck that would double down on anti-LGBTQ discrimination. North Carolinians want a clean repeal of HB2, and we urge our allies not to sell us out".

Mr Sgro added on Thursday that legal challenges could follow if lawmakers approved the measure.

Human Rights Campaign president Chad Griffin said: "At its core, it's a state-wide prohibition on equality."

Businesses, entertainers and sports teams had boycotted North Carolina in the wake of the law's passage last year.

Its largest city, Charlotte, lost the National Basketball Association (NBA) All-Star game, which was moved to another state.

"Basketball is important to North Carolina; nobody is going to deny that," Senator Ralph Hise told the Charlotte Observer.

"But we've been threatened as a state and we took the coward's act and we're backing down. I can't stand for that," he said.

Republican Sen Dan Bishop, an author of HB2, called the compromise "at best a punt, at worst it is a betrayal of principle".

Who and what have boycotted North Carolina?

Paypal

Deutsche Bank

Bruce Springsteen

Pearl Jam

The band Boston

Demi Lovato

Nick Jonas

Cirque de Soleil

National Collegiate Athletic Association (NCAA) basketball, golf and swimming

ACC Swimming and Diving Championships

North Carolina was on Thursday set to lose its ability to host any college (NCAA) basketball championships from 2018 to 2022 "absent any change" in the House Bill 2.

The controversial bill will cost the state more than $3.67bn in lost business over 12 years, according to a recent Associated Press analysis.

Mr Cooper beat Republican Pat McCrory, who had signed the law, in an election in December.

The then-governor-elect attempted to reach a compromise over the law during a special session in December, but failed.

Critics of the bill say it has encouraged lawmakers in other states to put forward their own version of House Bill 2.

As of March, 16 states were considering bathroom bills, according to the National Conference of State Legislatures.

Among those states are Texas, Tennessee, Arkansas, Illinois and Minnesota.