Sen. Bernie Sanders, I-Vt., narrowly won the New Hampshire primary Tuesday night, catapulting the 78-year-old self-described democratic socialist to the front of the still-crowded Democratic presidential primary field.

Sanders had been leading top rival Pete Buttigieg and several other candidates as results came in throughout the evening, though only by a fraction of his 22-point margin of victory over Hillary Clinton in the 2016 New Hampshire primary. Buttigieg, meanwhile, touted his strong second-place finish as a sign that his campaign was "here to stay."

"Thank you New Hampshire," Sanders told cheering supporters late Tuesday, saying his campaign had won a "great victory."

"The reason that we won tonight in New Hampshire, we won last week in Iowa -- is because of the hard work of so many volunteers," Sanders continued. "And let me say tonight that this victory here is the beginning of the end for Donald Trump."

New Hampshire's first-in-the-nation presidential primary came days after Sanders won the popular vote in the botched Iowa caucuses. Buttigieg took home more delegates from that contest, however.

At the same time, Buttigieg wasn't the only Democrat standing between Sanders and the nomination. A late-surging Minnesota Sen. Amy Klobuchar landed in third place in New Hampshire as votes continued rolling in.

Sanders and Buttigieg will likely each receive nine delegates to the Democratic National Convention after Tuesday's primary, because the state awards them proportionally; Klobuchar will receive six. Those numbers are a fraction of the 1,991 delegates needed for the nomination, but early primaries play an outsized role in candidate fundraising and momentum.

Klobuchar, in remarks earlier in the evening, said her heart was "full" and that "we have beaten the odds every step of the way -- we have done it on the merits, we have done it with ideas, and we have done it with hard work."

In a disappointing night for both of them, Massachusetts Sen. Elizabeth Warren will finish fourth and former Vice President Joe Biden will finish fifth -- even worse than his fourth-place finish in Iowa. The development was especially problematic for Warren, a known quantity in the New England political world who had long polled ahead of Klobuchar nationally.

With 85 percent of precincts reporting, Sanders had 25.8 percent of the vote; Buttigieg 24.4 percent; Klobuchar 19.7 percent; Warren 9.3 percent; and Biden 8.4 percent. Sanders received approximately 69,738 votes to Buttigieg's 65,956, Klobuchar's 53,265, Warren's 25,232, and Biden's 22,616.

Trump, watching from the sidelines on Twitter, mocked each Democratic contender in turn late Tuesday. "Bootedgeedge (Buttigieg) is doing pretty well tonight," Trump wrote. "Giving Crazy Bernie a run for his money. Very interesting!"

In a reference to former New York City Mayor Mike Bloomberg, Trump added: "A very bad night for Mini Mike!"

Bloomberg was showing signs of strength in polling around the country but wasn't on the New Hampshire ballot. The president highlighted Bloomberg's comments during a 2015 appearance at the Aspen Institute in which he said the way to bring down murder rates was to "put a lot of cops" in minority neighborhoods because that's where "all the crime is."

Trump also celebrated his expected win in Tuesday's New Hampshire Republican primary: "The Fake News Media is looking hard for the Big Democrat Story, but there is nothing too fabulous. Wouldn’t a big story be that I got more New Hampshire Primary Votes than any incumbent president, in either party, in the history of that Great State? Not an insignificant fact!"

BLOOMBERG DISCUSSES THROWING MINORITY KIDS UP AGAINST THE WALL IN RESURFACED AUDIO

At Sanders headquarters late Tuesday night, loud boos erupted as Buttigieg took the stage to thank supporters, in yet another sign of escalating tensions in the primary contest.

“A campaign that some said shouldn’t be here at all has shown that we are here to stay," Buttigieg declared. He later took a thinly veiled shot at Sanders, insisting that "a politics of my way or the highway is the road to re-electing Donald Trump.”

In a tacit acknowledgment that he was in for a rough night, Biden already left New Hampshire and headed to South Carolina hours before polls began closing at 7 p.m. ET.

As precincts began reporting his low vote totals, Biden addressed his supporters in New Hampshire via livestream from South Carolina.

“I do love New Hampshire, and I mean it,” Biden said. “Now Jill and I are moving on to Nevada and South Carolina and beyond. ... “We’re going on and we’re going to win in Nevada and in South Carolina.”

Speaking minutes later to a more lively crowd in Columbia, South Carolina, Biden told attendees, "We've just heard from the first two of the 50 states. ... Where I come from, that's the opening bell. Not the closing bell. And the fight to end Donald Trump's presidency is just beginning."

Warren, as results came in, acknowledged that Buttigieg and Sanders were doing well, and praised Klobuchar's strong performance. But, she also condemned the increasingly harsh tone in the race.

"Harsh tactics might work if you’re willing to burn down the party," Warren admonished.

New Hampshire will send a total of 24 pledged delegates to the Democratic National Convention, accounting for just one percent of the total delegates available nationwide.

Sixteen of the delegates are awarded proportionally by congressional district, while eight are determined by statewide vote. Nine of the delegates are less important "automatic delegates" who can't participate in the convention in the first round of voting unless one candidate has an overwhelming lead.

Candidates must receive 15 percent of the vote either statewide or in at least one congressional district to receive any delegates, which is the rule for all Democratic primaries and campaigns.

The night saw two departures from the race, even before all the votes were counted: Colorado Sen. Michael Bennet and Andrew Yang. ("A lot of Democrat dropouts tonight, very low political I.Q.," mused Trump on Twitter.)

Yang told cheering supporters Tuesday night that he's "just getting started." Attendees responded by cheering, "2024! 2024!"

“There’s part of me that feels disappointed, like I didn’t fulfill some people’s goals for this campaign,” Yang told BuzzFeed News earlier in the day. “There’s also a competitive part of me too — like I can’t believe I lost to these people.”

More than a year after Democrats began announcing their presidential candidacies, the party is struggling to coalesce behind a message or a messenger in its desperate quest to defeat Trump.

That raised the stakes of the New Hampshire primary as voters weighed whether candidates were too liberal, too moderate or too inexperienced — vulnerabilities that could play to Trump's advantage in the fall.

BIDEN BAILS: FORMER VP LEAVES NEW HAMPSHIRE EARLY, ABANDONING ELECTION NIGHT PARTY

Some candidates sought to undercut the importance of the New Hampshire election, but history suggested otherwise. No Democrat has ever become the party's presidential nominee without finishing first or second in New Hampshire.

Trump, campaigning in New Hampshire Monday night, sought to inject chaos in the process, even as he mocked top Democrats and touted his successes in office.

WATCH: TRUMP DERIDES 'MUMBLING' PELOSI AND URGES REPUBLICANS TO TURN OUT IN FORCE

He even suggested that conservative-leaning voters could affect the state's Democratic primary results, though only registered Democrats and voters not registered with either party can participate in New Hampshire's Democratic presidential primary.

“I hear a lot of Republicans tomorrow will vote for the weakest candidate possible of the Democrats,” Trump said Monday. “My only problem is I’m trying to figure out who is their weakest candidate. I think they’re all weak.”

Some top Democrats appeared to recognize that onetime frontrunners were now in the back of the pack.

New Hampshire House Speaker Steve Shurtleff, who endorsed Biden less than a month ago, spoke about him over the weekend as if he were already eliminated from contention.

AWKWARD: VOTER TELLS MSNBC THAT UNFAIR COVERAGE TO SANDERS IMPACTED HER VOTE

“I hope the vice president does well, and I hope he can move forward, but it’s hard to say,” Shurtleff said. “The sad thing for me personally is that he's such a terrific individual.”

Biden's campaign, meanwhile, sought to cast New Hampshire as one small step in the path to the presidential nomination, with contests coming up in more diverse states that award more delegates including Nevada and South Carolina, where Biden hopes to retain his advantage among minority voters.

“Regardless of what happens on Tuesday, we plan to move forward,” Biden senior adviser Symone Sanders said.

The night was stinging for Warren, given that the New Hampshire contest was set just next door to her Massachusetts home. She has positioned herself as a mainstream alternative to Bernie Sanders but is suddenly looking up at him and Buttigieg as Klobuchar fights to peel away female support.

Warren released an afternoon memo seeking to downplay New Hampshire's results. Campaign manager Roger Lau outlined a “path to victory” through 30-plus states where the campaign has paid staff on the ground as he highlighted alleged weaknesses in Warren's Democratic rivals.

Buttigieg, young and with no governing experience beyond the mayor's office, is trying to emerge as the leading Biden alternative for his party's moderate wing. In the days leading up to Tuesday’s primary, Buttigieg has come under increasing attack from Biden and Klobuchar, who emphasized his lack of experience.

Sanders has been one of the only candidates to explicitly predict victory in New Hampshire, where he defeated Hillary Clinton by more than 20 percentage points four years ago.

CLICK HERE TO GET THE FOX NEWS APP

Sanders spent the eve of the primary courting his most passionate supporters, young voters, at two college campuses.

At a Monday night rally at an arena on the University of New Hampshire campus, a band pumped up the crowd with a cover of The Who’s “My Generation,” before Sanders and Rep. Alexandria Ocasio-Cortez, a leading figure among young progressives, took the stage.

Fox News' Andrew Craft, Paul Steinhauser and The Associated Press contributed to this report.