WASHINGTON — Bernie Sanders won New Hampshire’s presidential primary election Tuesday night, narrowly edging moderate rival Pete Buttigieg and scoring the first clear victory in the Democratic Party’s chaotic 2020 nomination fight.

In his win, the 78-year-old Sanders, a self-described democratic socialist, beat back a strong challenger from the 38-year-old former Midwestern mayor -- two men representing different generations and wings of their party.

Addressing supporters Tuesday night, Sanders claimed victory in New Hampshire and pledged that if he becomes the Democratic nominee, he will unite a fractured party to defeat President Donald Trump.

"This victory here is the beginning of the end for Donald Trump,” Sanders declared.

Amy Klobuchar finished third while Elizabeth Warren finished a distant fourth, and Joe Biden came in fifth. Warren and Biden were on track to finish with zero delegates from the state. However, both said they would stay in the race, and Biden was already in next-up South Carolina.

A pair of Joe Biden surrogates tried their best to mask a disappointing night for the absent Democratic presidential candidate at his campaign’s New Hampshire watch party.

Biden originally planned to attend, but his campaign announced late Tuesday morning that that he would instead hold an event in South Carolina.

A triumphant Pete Buttigieg says he is ready to take his Democratic presidential campaign to the rest of the nation after a strong finish in New Hampshire.

The audience in the gymnasium in Nashua was electric Tuesday as supporters chanted, “Boot-edge-edge, Boot-edge-edge!” — the familiar phonetic of the candidate's unusual name.

“Now our campaign moves on to Nevada and South Carolina and across the country, and we will welcome new allies to our movement at every step,” the former mayor of South Bend, Indiana, told a crowd of supporters.

Buttigieg vowed to “end the era of Donald Trump,” while keeping up pressure on his top rival, Vermont Sen. Bernie Sanders, who he said was taking a “my-way-or-the-highway approach.”

He also tweaked the surging Minnesota Sen. Amy Klobuchar, who looked to finish in third place.

Klobuchar has been a sharp critic of Buttigieg’s, noting that he's served two terms as the mayor of a city of about 103,000, while she’s been elected statewide three times in Minnesota.

“I know that if you talk this way, you might be dismissed as a naive newcomer,” Buttigieg said. "But a fresh outlook is what makes new beginnings possible.”

Two other Democratic candidates dropped out after polls closed in New Hampshire. Entrepreneur Andrew Yang and Colorado Sen. Michael Bennet ended their White House runs after disappointing finishes Tuesday.

Democrat Andrew Yang, an entrepreneur who created buzz for his presidential campaign by championing a universal basic income that would give every American adult $1,000 per month, suspended his 2020 bid on Tuesday.

RELATED: Yang, Bennet end 2020 Democratic presidential bids

After dropping out of the Democratic presidential primary race, Andrew Yang said that he felt his message resonated but that voters wanted someone with a “different profile that they had felt a higher degree of familiarity with and security with.”

Colorado Sen. Michael Bennet also ended his 2020 Democratic presidential bid after he pinned his campaign's hopes on New Hampshire.

President Donald Trump has easily won New Hampshire’s Republican primary against minimal opposition.

Party leaders hoped the night would bring at least some clarity to a presidential nomination fight that has so far been marred by dysfunction and doubt. 

Former Massachusetts Gov. Deval Patrick said he will “reflect” on his lackluster showing in the New Hampshire primary and would soon “make some decisions” on the future of his Democratic presidential campaign. 

Patrick, who entered the race in November, had said that a strong showing in New Hampshire was needed to have a credible shot at winning the nomination. But he trailed far behind the leading contenders in early election returns.

By night's end, New Hampshire could begin culling the Democrats' unwieldy 2020 class, which still features nearly a dozen candidates battling for the chance to take on President Donald Trump this fall.

Hours before the rest of the voting locations opened up, voters in three small towns cast the first ballots in the New Hampshire primaries and Sen. Amy Klobuchar of Minnesota has the early lead. And in a write-in twist, one candidate received votes as both a Democrat and a Republican.

With all the ballots in Dixville Notch, Millsfield and Hart's Location tabulated just after midnight, Klobuchar had eight votes. Sen. Bernie Sanders of Vermont and Sen. Elizabeth Warren of Massachusetts were tied with four votes. Entrepreneur Andrew Yang has three votes. Former Vice President Joe Biden and former mayor Pete Buttigieg had two votes.

Election 2020 New Hampshire
Richard Mellon and Tom Duston hold up signs for Democratic presidential candidate Sen. Elizabeth Warren, D-Mass., outside the Chesterfield, N.H., Town Hall during the New Hampshire presidential primary elections, Tuesday, Feb. 11, 2020. (Kristopher Radder/The Brattleboro Reformer via AP)
AP

RELATED: Yang, who created buzz with freedom dividend, ends 2020 bid

In Dixville Notch, former New York City Mayor Michael Bloomberg appeared as a write-in candidate with two votes on the Democratic side and one vote on the Republican side. Bloomberg has been a Democrat, Republican and independent in his career.

Rep. Tulsi Gabbard and businessman Tom Steyer each received only one Democratic vote.

RELATED: Who is running for president in 2020?

RELATED: VERIFY: Does winning the New Hampshire Primary actually matter?

President Donald Trump, expected to easily win the Republican contest, was leading by a wide margin following the early vote. But it was not unanimous. In addition to a vote for Bloomberg, there were five votes for former Massachusetts Gov. Bill Weld and one vote for Mary Maxwell.

Tuesday's first-in-the-nation primary (last week's contest in Iowa was a caucus, not a primary) could be an early sign for which campaigns will have staying power at least through Super Tuesday in three weeks and which ones may have to fold up tents even before the next two contests in Nevada and South Carolina.

After ending up in a virtual tie with Sanders in Iowa, Buttigieg received a boost in polling late last week, but there were signs over the weekend of that support fading following his performance in last Friday's debate in which the other candidates piled on the criticism. 

Klobuchar, who was seen as having a strong debate, has boasted about picking up $3 million in donations over the weekend. She's also seen a boost in recent polls projecting a third-place finish in New Hampshire.

Candidates were taking varied approaches ahead of the primary. Sanders is embracing high expectations.

“If we win here tomorrow, I think we've got a path to victory for the Democratic nomination," Sanders declared.

Sanders got a boost Monday from a nationwide Quinnipiac poll that put him ahead of former Vice President Joe Biden for the first time, 25 percent to 17 percent among Democrats and Democratic-leaning voters.

Klobuchar seemed optimistic as she held a rowdy event at a Manchester bar Monday, buoyed by a string of New Hampshire newspaper endorsements, fundraising and positive polls.

“The heart of our nation is bigger than the heart of this guy in the White House," she told supporters. 

Buttigieg on Monday night keyed in on Sanders' ambitious “Medicare for All” proposal as being among a slate of plans that are fiscally unmanageable.

Biden is lowering expectations as he faces the prospect of finishing well off the pace after a fourth-place finish in Iowa. Still, he is reminding voters, “This is just getting started.”

Warren is somewhere in between — not promising victory but instead saying she's poised for a comeback.

The Associated Press contributed to this report.