The irate conservative leaders of the state legislature, convinced this represented a threat to public safety, convened a one-day emergency session to overrule the ordinance. But the bill they drafted, the Public Facilities Privacy and Security Act — better known as House Bill 2 — went much further than regulating bathrooms. H.B. 2 revoked every local nondiscrimination ordinance in the state, replacing them all with a single policy that explicitly excluded sexual orientation and gender identity as protected classes. It then expressly made it illegal for people to enter bathrooms in publicly funded facilities such as airports, schools and arenas that did not correspond to their “biological sex,” which the law defined as the gender on their birth certificate.

McCrory signed the bill that night. When I asked him why, he told me he had thought about Mike Pence, the Indiana governor who has since become Donald J. Trump’s running mate. Pence courted national controversy in 2015 when he took three days to sign a bill that allowed Indianans to ignore some nondiscrimination protections on grounds of “religious freedom.”

Under threats of boycott from corporations, as well as the N.C.A.A., Pence signed an amendment granting limited protections based on race and sexual orientation, which made no one happy. Decisive action, McCrory thought, would keep L.G.B.T. rights groups like the Human Rights Campaign from turning H.B. 2 into a liability for his re-election bid against the longtime Democratic state attorney general, Roy Cooper. “I knew it was a political setup,” he told me. “I’m no fool.”

McCrory also knew that, while he had to appeal to the conservative base that supported the bill, he had to keep the backing of suburban moderates who pushed him to victory in 2012. So he attempted some political tap-dancing, defending the controversial law as “common sense” even as he strongly implied that he had nothing to do with its creation.

Throughout our interview, McCrory took pains to contrast himself with the social conservatives in the Statehouse down the street and highlighted his opposition to other conservative legislation including a “religious freedom” bill that more closely resembled Indiana’s. McCrory also noted his refusal to call the special session in which H.B. 2 was passed. He stopped just short of suggesting his own party should lose seats in the fall. “You know a supermajority gives more power to the legislature than the executive branch,” he said. “You talk to any governor and we’re all going through the same thing.” But Republican strategists in the state, as well as other officials and lobbyists who have talked with McCrory and his staff about the issue, told me the governor’s office did take a leading role in pushing for the bill.

Before McCrory signed the legislation, a lobbyist under contract with Apple tried to set up a phone call between the governor and an Apple executive to discuss it, said Darren G. Jackson, a Democratic state legislator who later met with the company’s representatives. Apple is a major investor in North Carolina, operating a $3 billion iCloud data center and solar farm in Maiden. Tim Cook, its openly gay C.E.O. who went to business school at Duke University vehemently opposes the law.

McCrory’s office never responded to the request. (Apple declined to comment for this story.) Instead, McCrory’s chief campaign strategist, Chris LaCivita — who organized the Swift Boat Veterans for Truth campaign against John Kerry in 2004 — wrote the contract lobbyist, who represents several firms opposed to the bill, and others trying to persuade legislators to vote against the law, to let them know he was watching them. “Pressure was being put on lobbyists and the business community to stay out of it,” Jackson said. (LaCivita declined to comment on the emails.)