Concord, New Hampshire - United States Senator Bernie Sanders declared victory in New Hampshire on Tuesday night after he narrowly beat Pete Buttigieg in the state's Democratic primary.

Sanders, who led the polls going into the vote, had 26 percent with nearly all the precincts reporting.

Former South Bend, Indiana, Mayor Buttigieg followed with 24.4 percent and Minnesota Senator Amy Klobuchar had 19.7 percent.

More:

"Let me thank the people of New Hampshire for the great victory tonight," Sanders, a progressive, told supporters.

"This victory here is the beginning of the end for Donald Trump," the 78-year-old self-described democratic socialist said as the crowd roared in support.

Despite a modest turnout, Sanders generated enough voter excitement to emerge as the new Democratic frontrunner - with former Vice President Joe Biden leaving the state early to South Carolina.

"The enthusiasm for Bernie is real," said Marilyn Martin, a campaign volunteer in the state capital, Concord.

Martin described the campaign's energy as "absolutely electric" and said a New Hampshire bounce would give the senator from Vermont "momentum to push forward".

Democratic US presidential candidate and former South Bend Mayor Pete Buttigieg speaks to supporters at his New Hampshire primary night rally in Nashua, New Hampshire [Brendan McDermid/Reuters]

Despite Sanders's win, he is expected to get the same number of delegates as Buttigieg due to the way delegates are awarded in the state.

Buttigieg, 38, congratulated Sanders on his "strong showing". But the more moderate candidate told supporters: "So many of you chose to meet a new era of challenge with a new generation of leadership."

With a strongly independent and libertarian bent, New Hampshire lacks the diversity typical of many states where primaries will soon take place. Some argue that the sparsely populated and homogenous state is not representative of the country, saying it is not an important indicator or should not continue in its bellwether role.

But Sanders supporters hope to receive a boost from vanquishing the deep Democratic field, earning a symbolic victory in a tense election process.

"There's a coalition that [Sanders] has been building among Latino voters, African American voters, Muslim voters," Martin told Al Jazeera. "I'm pretty sure New Hampshire is his. He won it by a very significant margin in 2016."

Democratic presidential candidate Senator Amy Klobuchar greets supporters outside a New Hampshire primary polling location [Holly Ramer/AP Photo]

For her part, Klobuchar, who analysts say had an especially strong showing after a standout performance at Friday's Democratic debate, said her campaign "came back, and we delivered".

"America deserves a president who is as resilient as her people," she told supporters in New Hampshire.

Senator Elizabeth Warren of Massachusetts initially polled ahead in the state before seeing her fortunes decline. She was expected to come in fourth place, just ahead of Biden. Warren and Biden are not expected to win any delegates in the state.

Warren, not waiting for the final results to roll in, addressed supporters and congratulated Sanders and Buttigieg on their strong showings in the state.

They're both "strong candidates", she said, but added that she was still the best candidate to unite the Democratic Party.

"The fight we're in, the fight to save our democracy, is an uphill battle, but our campaign is built for the long haul and we're just getting started," Warren said.

Democratic 2020 US presidential candidate and US Senator Elizabeth Warren greets supporters outside a polling site for New Hampshire's first-in-the-nation primary in Nashua, New Hampshire [Brian Snyder/Reuters]

Billionaire businessman Tom Steyer and Hawaii Congresswoman Tulsi Gabbard followed Biden, with former Massachusetts Governor Deval Patrick trailing far behind.

New Hampshire's primary took place just eight days after the chaotic Iowa caucuses in which no candidate was declared the winner. Sanders and Buttigieg virtually tied in that state, with both candidates calling for a recanvass of the results.

Yang, Bennet drop out

Meanwhile, long-shot candidate Andrew Yang, an entrepreneur who has no political experience but gained some level of popularity touting what his supporters considered to be novel ideas, announced on Tuesday evening that he was ending his campaign. Yang told supporters, however, that his "movement was the future of the Democratic Party".

Colorado Senator Michael Bennet also suspended his bid for the presidency.

A man wearing a stars and stripes hat votes in the primary election at a polling station in Epping, New Hampshire [Kevin Lamarque/Reuters]

While much of the attention in New Hampshire was focused on the Democratic race, there was something of a surprise on the other side. President Donald Trump, with only one name-brand challenger in former Massachusetts Governor Bill Weld, handily won the Republican primary, but not by nearly the margin he enjoyed in Iowa.

Trump, with two challengers in Iowa, won more than 97 percent of the votes there. In New Hampshire, by contrast, he was on track to win only 85 percent of the vote. Weld racked up about 10 percent of the tally, and the remainder of the votes went to "Other".

"Underperforming," was the adjective used by several pundits on US cable news to describe Trump's showing.

Weld acknowledged his campaign may not last.

"Any centrist Democrat would be fine with me" to take on Trump, Weld told Al Jazeera before the polls closed on Tuesday.

New Hampshire gave Trump his first primary win in the 2016 election. He narrowly lost the state to Democrat Hilary Clinton in the 2016 general election.

Trump held a campaign rally in Manchester on Monday night, seeking to highlight divisions within the Democratic party.

Next up: Nevada, South Carolina

After New Hampshire, most candidates will turn their attention to Nevada, which is set to hold its caucuses on February 22. South Carolina will head to the polls a week later on February 29 before Super Tuesday on March 3 when the largest number of delegates are up for grabs in a single day.

Biden, who conceded he would not top the leaderboard in New Hampshire, is hoping to capitalise on his support among African Americans in South Carolina. His poor performances in Iowa and New Hampshire were a blow to his campaign, which was hoping to gain momentum after dipping in the polls.

Biden speaks to supporters at a campaign event in Manchester, New Hampshire [Carlos Barria/Reuters]

"We just heard from the first two of the states," Biden told supporters in South Carolina, "where I come from, that's just the opening bell, not the closing bell."

The former vice president said many Democrats do not listen to African American voters.

"I've never not listened to you," he said. "You can't be the Democratic nominee, you can't win a general election as a Democrat, unless you have overwhelming support from black and brown voters."

Back in New Hampshire, Sanders's supporters celebrated his strong showing.

"I just appreciate all of his platforms and how he looks at power structures, not just at the problems on the ground," Savitri Horrigan told Al Jazeera at the Sanders victory rally on the campus of Southern New Hampshire University.

Austin Manny said he was happy to see his candidate advocating for the benefits such as Medicare-for-all and the Green New Deal, which addresses climate change.

Sanders is "the only one that can fix these science-based issues", Manny told Al Jazeera.

"Congressionally it'll be really hard to get any of this stuff done, so you need a movement of people behind it," he told Al Jazeera.

"Bernie is fully small-donor supported," Manny added. "You have to have skin in the game."