In one of the nation’s most closely watched races, Thom Tillis, the Republican speaker of the North Carolina House, narrowly won a Senate seat against Kay Hagan, a first-time Democratic senator. For months, Ms. Hagan, a prime Republican target, led in the polls, but Mr. Tillis closed the gap in the final days of the race.

Mr. Tillis, 54, asserted that Ms. Hagan, 61, was President Obama’s ideological clone, while she called him too conservative for the state, which went for Mr. Obama in 2008 before flipping to Mitt Romney in 2012. Helped by Mr. Obama’s 2008 victory, Ms. Hagan that year defeated Elizabeth Dole, 53 percent to 44 percent.

The Hagan campaign criticized Mr. Tillis for supporting restrictions on voters, resisting Medicaid expansion, slashing jobless benefits and supporting deep cuts in the state’s education budget, before the Legislature voted to increase school spending this year. Mr. Tillis accused her of being too liberal for North Carolina by supporting the Affordable Care Act.

Despite Mr. Tillis’s attacks, Ms. Hagan did not disassociate herself from Mr. Obama, but she did underline her differences with him: about the oversight of veterans’ hospitals, the Keystone XL pipeline debate, immigration and trade agreements. The National Journal has called her “the most moderate senator in the nation.”

Exit polls found that the Affordable Care Act was not a major factor in the race, with 48 percent of North Carolina voters saying the law did not go far enough or was about right, while 46 percent said it went too far. Of those who voted for Ms. Hagan, 83 percent thought the health care law did not go far enough or was about right. Of the 46 percent who thought the law went too far, 80 percent voted for Mr. Tillis.