RALEIGH, N.C. — North Carolina leaders struck a deal Monday to kill the state law widely derided as the “bathroom bill,” after it tarnished the state’s reputation, cost it scores of jobs and contributed to the Republican governor’s narrow loss.

Outgoing Gov. Pat McCrory announced he will call legislators back to the Capitol on Wednesday to repeal the law known as HB2, which excludes sexual orientation and gender identity from antidiscrimination protections. The law also requires transgender people to use restrooms corresponding with the sex on their birth certificate in many public buildings.

Undoing the law would be a step toward mending political divisions that remain raw well after Election Day. Just last week, lawmakers called a special session to strip Democratic Gov.-elect Roy Cooper of some authority before he takes office next month.

The state’s Republican leaders confirmed they’re open to repealing HB2, but in a sign of lingering acrimony, they accused Cooper of taking too much credit for winning their cooperation.

The passage of HB2 in March thrust North Carolina into a national debate on transgender rights and harmed the state economically. The state missed out on new jobs as companies declined to expand in the state, while cancellations of concerts and conventions exacted a toll. The NBA moved its All-Star game to New Orleans, and in a huge symbolic blow to the college basketball-crazy state, the NCAA and ACC relocated events.

Monday’s surprising events began in the morning when the Charlotte City Council voted to undo a local nondiscrimination law enacted in early 2016. That ordinance, Republicans legislators say, challenged social norms and spurred them to pass HB2.

McCrory said Democrats used the issue for political gain.

“This sudden reversal with little notice after the gubernatorial election sadly proves this entire issue, originated by the political left, was all about politics and winning the governor’s race at the expense of Charlotte and the entire state of North Carolina,” said McCrory, a former Charlotte mayor.