CONCORD, N.H. — Republican U.S. Sen. Kelly Ayotte conceded defeat to her Democratic challenger, Gov. Maggie Hassan, on Wednesday, ending what for months had been one of nation’s most closely watched contests.

The secretary of state’s office showed Hassan with a lead of 1,023 votes out of 738,420. Ayotte, who was elected in 2010, offered her congratulations to Hassan on Wednesday afternoon.

“This is a critical time for New Hampshire and our country, and now more than ever, we need to work together to address our challenges,” she said. “The voters have spoken and now it’s time for all of us to come together to get things done for the people of the greatest state in this nation and for the greatest country on Earth.”

Hassan had claimed victory hours earlier, telling cheering supporters outside the Statehouse that she was confident she’d maintain a lead once all the votes were counted.

“I am proud to stand here as the next United States senator from New Hampshire,” she said.

The tight race between Hassan and Ayotte was viewed as one of half a dozen contests around the country that would determine which party controls the Senate next year. But by late Tuesday night it was clear Republicans would officially retain control regardless of New Hampshire’s outcome.

Further down the ballot, Republican Chris Sununu defeated Democrat Colin Van Ostern in the governor’s race, Democrat Carol Shea-Porter ousted Republican U.S. Rep. Frank Guinta in the 1st Congressional District, and Democratic U.S. Rep. Annie Kuster defeated Republican Jim Lawrence in the 2nd Congressional District.

The Senate race attracted attention from the start given the stakes, and interest intensified after Donald Trump became the Republican presidential nominee. After months of saying she supported but wasn’t endorsing him, Ayotte rescinded her support in October and said she would write in vice presidential nominee Mike Pence instead.

Ayotte, a former attorney general, argued that, unlike Hassan, she had been willing to stand up to her party’s leadership. She cast herself as an independent, bipartisan senator while portraying Hassan as a rubber stamp for Democrats and a hypocrite for taking credit for a state budget she initially vetoed as governor.

But Hassan, a two-term governor, brought up Trump frequently, arguing that Ayotte showed bad judgment in supporting him for as long as she did and put political calculations ahead of principle when she changed her position. On Wednesday, she said she will work with Trump when doing so serves New Hampshire’s interests and will stand up to him when it doesn’t.

“We know that this election exposed very serious divisions in our country, and it’s up to all of us – elected leaders and citizens – now to come together and focus on our common challenges and our common opportunities,” she said. “Our work going forward is going to be to remember what unites us as Americans and how we can make progress together.”

Hassan will be the second woman in U.S. history to serve as both governor and senator. New Hampshire’s other U.S. senator, Democrat Jeanne Shaheen, was the first.