With loud cheers and applause, New Hampshire lawmakers on Wednesday re-elected their veteran secretary of state and guardian of the first-in-the-nation presidential primary after two rounds of close votes.

Legislators voted to keep Bill Gardner, the nation's longest-serving secretary of state. He has held the job for 42 years.

"I'm very, very grateful to those of you who let this happen," Gardner told them afterward. "That office is so unique and so special."

Legislators voted twice; neither candidate won a majority the first time. The final vote was 209-205 for Gardner over challenger Colin Van Ostern, a 2016 gubernatorial candidate who wasn't even born when Gardner first took office.

Gardner was criticized for serving on President Donald Trump's election fraud commission. But his supporters argued that replacing him with fellow Democrat Van Ostern would politicize the office and could weaken the state's argument for staying first.

Van Ostern countered that primary tradition is about more than any one person and that Gardner already politicized the office by backing GOP-led voter legislation to tighten voter registration rules.

Democrats won control of both the 400-member House and 24-member Senate last month, and they overwhelmingly backed Van Ostern in a nonbinding caucus vote Nov. 15.

Van Ostern, who served as an executive councilor in addition to running for governor, said last week, "I will not run from this office for any other job."

The secretary of state serves a two-year term. "I think it will probably take more than two years to bring the changes we need after 42 years without a change in leadership," he said.

Gardner said the trust he earned by pledging not to use the office as a stepping stone for higher office has helped him negotiate the often-fraught scenario of protecting the primary.

Van Ostern raised and spent more than $200,000 to defeat him, but Gardner said he viewed this challenge as he did others in the past.

Republican Gov. Chris Sununu backed Gardner's re-election, as did most of New Hampshire's living former governors. Gardner, he said, has acted with "absolute independence and incorruptible motive," calling the effort to replace him a "strategic political operation." Democratic former Govs. Jeanne Shaheen and Maggie Hassan didn't take sides.

Gardner was long credited with protecting the state's first-in-the-nation presidential primary status. Some worried that with him gone, that would be threatened in the future.

Van Ostern promised to fiercely defend New Hampshire's position in the presidential nominating calendar.

The New Hampshire primary is a time-honored tradition in politics. In 1916, Indiana held its primary a week before New Hampshire, and Minnesota voted on the same day. But New Hampshire has gone first ever since.