MANCHESTER, N.H. -- Bernie Sanders won New Hampshire's presidential primary, edging moderate rival Pete Buttigieg and scoring the first clear victory in the Democratic Party's chaotic 2020 nomination fight.

In his Tuesday night win, the 78-year-old Sanders, a self-described democratic socialist, beat back a strong challenge from the 38-year-old former mayor of South Bend, Indiana. The dueling Democrats represent different generations, see divergent paths to the nomination and embrace conflicting visions of America's future.

As Sanders and Buttigieg celebrated, Amy Klobuchar scored an unexpected third-place finish that gives her a road out of New Hampshire as the primary season moves on to the string of state-by-state contests that lie ahead.

Elizabeth Warren and Joe Biden posted disappointing fourth and fifth place finishes respectively and were on track to finish with zero delegates from the state.

The New Hampshire vote gives new clarity to a Democratic contest shaping up to be a battle between two men separated by four decades in age and clashing political ideologies. Sanders is a leading progressive voice, having spent decades demanding substantial government intervention in health care and other sectors of the economy. Buttigieg has pressed for more incremental change, preferring to give Americans the option of retaining their private health insurance while appealing to Republicans and independents who may be dissatisfied with Trump.

Their disparate temperaments were on display Tuesday as they spoke before cheering supporters.

"We are gonna win because we have the agenda that speaks to the needs of working people across this country," Sanders declared. "This victory here is the beginning of the end for Donald Trump."

Buttigieg struck an optimistic tone: "Thanks to you, a campaign that some said shouldn't be here at all has shown that we are here to stay."

Both men have strength heading into the next phase of the campaign, yet they face very different political challenges.

While Warren made clear she will remain in the race, Sanders, well-financed and with an ardent army of supporters, has cemented his status as the clear leader of the progressive wing of the party.

Meanwhile, Buttigieg must prove he can attract support from voters of colour who are critical to winning the nomination. And unlike Sanders, he still has multiple rivals in his own ideological wing of the party to contend with. They include Klobuchar, whose standout debate performance led to a late surge in New Hampshire and a growing national following. While deeply wounded, Biden promises strength in upcoming South Carolina. And though former New York Mayor Mike Bloomberg was not on Tuesday's ballot, he looms next month when the contest reaches states offering hundreds of delegates.

After a chaotic beginning to primary voting last week in Iowa, Democrats hoped New Hampshire would help give shape to their urgent quest to pick someone to take on Trump in November. At least two candidates dropped out in the wake of weak finishes Tuesday night: moderate Colorado Sen. Michael Bennet and political newcomer Andrew Yang, who attracted a small but loyal following over the past year and was one of just three candidates of colour left in the race.

The struggling candidates still in the race sought to minimize the latest results.

Warren, who spent months as a Democratic front-runner, offered an optimistic outlook as she faced cheering supporters: "Our campaign is built for the long haul, and we are just getting started."

Having already predicted he would "take a hit" in New Hampshire after a distant fourth-place finish in Iowa, Biden essentially ceded the state. He travelled to South Carolina Tuesday as he bet his candidacy on a strong showing there later this month boosted by support from black voters.

Still, history suggests that the first-in-the-nation primary will have enormous influence shaping the 2020 race. In the modern era, no Democrat has ever become the party's general election nominee without finishing first or second in New Hampshire.

Sanders and Buttigieg were on track to win the same number of New Hampshire delegates with most of the vote tallied, with Klobuchar a few behind. Warren, Biden and the rest of the field were shut out, failing to reach the 15% threshold needed for delegates.

The AP allocated nine delegates each to Sanders and Buttigieg and six to Klobuchar.

The action was on the Democratic side, but Trump easily won New Hampshire's Republican primary. He was facing token opposition from former Massachusetts Gov. Bill Weld.

With most of the vote in, Trump already had amassed more votes in the New Hampshire primary than any incumbent president in history. His vote share was approaching the modern historical high for an incumbent president, 86.43% set by Ronald Reagan in 1984. Weld received about 9% of the vote of New Hampshire Republicans.

The political spotlight quickly shifts to Nevada, where Democrats will hold caucuses on Feb. 22. But several candidates, including Warren and Sanders, plan to visit other states in the coming days that vote on Super Tuesday, signalling they are in the race for the long haul.

------

Peoples reported from Washington. Associated Press writers Seth Borenstein and Zeke Miller in Washington, Will Weissert, Holly Ramer and Thomas Beaumont contributed from New Hampshire