An Elon University poll conducted from April 10 to 15 showed Mr. Cooper, the state’s longtime attorney general, leading Mr. McCrory 48 percent to 42 percent among registered voters. It was Mr. Cooper’s largest lead in the five polls that Elon has conducted in the last year.

But November is a long way off, and social issues reverberate in complex ways in a state that has a reputation for moderation but also produced Jesse Helms, the arch-conservative United States senator. Carter Wrenn, a longtime political strategist who worked with Mr. Helms, said Democrats had been winning arguments over the law of late. But he said Republicans would have time to make the case to voters that the law helps ensure privacy and security in public restrooms.

“We’re not sure how this is all going to turn out,” Mr. Wrenn said.

The issue is particularly troublesome for Mr. McCrory. Exit polls from 2012 show that he received the support of 49 percent of voters who described themselves as moderate and 19 percent of self-described liberals.

Mr. McCrory, 59, last week could barely contain his irritation that the law had taken center stage in the election, siphoning attention from his central message: that he has been a wise steward of the economy who had engineered what he and his team have branded the “Carolina Comeback.”

This hornet’s nest, he argued, was first kicked not by him, but by the Democratic City Council in Charlotte, which passed a nondiscrimination ordinance in February allowing transgender people to use men’s or women’s bathrooms. Before it passed, he said, he emailed the Council to warn it that if it changed “basic restroom and locker room norms,” he would be forced to support a state law overriding them.

On Thursday, he said he suspected that the entire matter had been orchestrated by Democrats and the Human Rights Campaign, a national gay rights group, to give Democrats an advantage in a tight governor’s race.