The historic gains Republicans made in North Carolina in 2012 — capturing both chambers of the legislatures as well as the governorship for the first time since 1870 — have come with a cost.

The lurch to the extreme right the state took in the following years has given Gov. Pat McCrory (R) a tough reelection battle, as the sharp partisan split in the state means that it would take only a small electoral shift to flip the governorship back to blue. The irony of McCrory’s current conundrum is that he won the governorship on his reputation of being a pragmatic problem-solver, but now is contending with a record that reflects a social conservative, hard-line agenda.

The drag of the anti-transgender legislation known as HB2 on his campaign is perhaps the greatest example, with a solid plurality voters in a recent poll saying his support of it makes them less likely to back him.

Recent polls show a back and forth race, with McCrory trading the lead with Roy Cooper, the Democratic attorney general. Overall, Cooper leads 46.4 to 45.4 in TPM’s PollTracker Average.

“If anything, it’s a little surprising that Cooper hasn’t opened a lead bigger than that,” Carter Wrenn, a longtime GOP operative in state, told TPM.

The governor has been entangled in a number of high-profile fights around bills pushed by cultural conservatives in the statehouse, not the least of which being HB2. The bill, which was rushed through the legislature and hastily signed by McCrory, overrode a Charlotte non-discrimination ordinance while banning trans people from using the bathrooms that match their gender identities in certain public facilities. It also eliminated the right to sue in state court for discrimination, a provision that proved so controversial the legislature and governor were forced to repeal it within weeks.

It’s not just the substance of the bill itself, but the fallout from it that has bogged down McCrory’s reelection, according to Ferrel Guillory, a former journalist in the state who is now a journalism professor at the University of North Carolina.

“It’s symbolic and political import goes beyond the detail of the law itself,” Guillory told TPM. “It’s helped defined the image and the politics of the incumbent Gov. Pat McCrory.”

As businesses, entertainers and sports organizations protested the law by canceling events in the state, McCrory stood firm, blaming everyone from “the sports and entertainment elite” to former staffers in the Clinton administration for the fallout.

Wrenn, the GOP operative, said he didn’t think HB2 would be a driving issue for voters at the ballot box, but acknowledged McCrory faced a problem with some voters who “have doubts about his ability.”

“People who are questioning McCrory are looking at him and saying, ‘I’m just not sure he’s done a good job,’” Wrenn said. “I don’t think they’re looking at him and saying, ‘Well, I am going to vote against him because he’s for HB2.’ I don’t think it’s a wedge issue in terms of moving votes.”

McCrory’s problems didn’t start with HB2. From the beginning of his term, he has faced a veto-proof GOP legislature — where gerrymandering has kept Republican seats safe — that has set the tone for the state’s agenda.

“The problem for McCrory has been his inability to carve out an independent identity from the Republican state legislature, which is clearly right of center than where North Carolina is,” said Mac McCorkle, a public policy professor at Duke who has consulted on Democratic campaigns in the state.

One of the first things GOP legislators did in 2013 was a pass a bill barring the expansion of Medicaid under Obamacare, a bill McCrory ultimately signed even as he as has signaled openness to expansion. Since then, Republicans have pushed through controversial legislation that cut unemployment benefits, expanded the use of the death penalty, imposed abortion restrictions and cut back voting access. (Key sections of the voting law were recently struck down by a federal appeals court in a stinging decision that found the law was intentionally passed to discriminate against African Americans.) The recent shooting of an African-American by a cop in Charlotte has renewed attention to a bill McCrory signed in July that restricts the release of video taken by police dashboard and body cameras.

“There has been no question that Governor McCrory has been rolled by the Republicans in the legislature time and time again” said Scott Falmlen, whose political consultant firm is doing some work for McCrory’s challenger, Roy Cooper’s campaign.

McCrory has denied that he has shifted to the right over the course of his governorship.

“The Charlotte political system has become much more liberal since I left,” he told the Charlotte Observer earlier this month. “I haven’t changed my political philosophy. The Charlotte political system has gone very far left.”

The 2013 session was punctuated by weekly protests outside the capitol known as “Moral Mondays,” led by civil rights groups and the religious left. In the GOP wave of 2014, North Carolina’s legislature was the only Southern state where Democrats were able to make gains, though Republicans held onto their veto-proof majority.

Education has developed into a major issue of the race, as teacher pay in North Carolina is among the worst in the country (though that’s not entirely McCrory’s fault.) McCrory has also caught flack for Republican legislation that expanded voucher programs and allowed charter schools to take over low-performing public schools.

“In many ways the legislation was driven by the legislature and he signed on to it, but he did not present himself in the North Carolina tradition of being an education advocate,” McCorkle said.

In the meantime McCrory’s opponent, Cooper, been able to out-fundraise the incumbent. He has raised a total of $12.7 million by the second period of 2016, according to his campaign, which said in a memo that it was “more at this point in the campaign than any other gubernatorial race in North Carolina history.” By comparison, McCrory has raised $8.7 million, according to the Charlotte Observer.

North Carolina is the textbook definition of a battleground state. President Obama won it in 2008 by less than 14,000 votes, while in 2012 it swung back red with Mitt Romney capturing a 2 percentage point margin of victory. The state is now considered a must-win for Donald Trump — though so far, Hillary Clinton appears to have invested much more in terms of a ground game, which may further benefit Cooper.

McCrory, who served for 14 years as the mayor of Charlotte, sold himself to his deeply purple state in 2012 as a “moderate, pragmatic not overly partisan, pro-business mayor,” said Gary Pearce, a Democratic consultant in North Carolina.

“He got elected because of Charlotte,” Pearce said. “And now there’s a big chance that he is going to lose because of Charlotte — he will lose votes there and he has got a reputation as more hard right and not pragmatic, and bad for business.”