Barack Obama, the winner five days ago in the Iowa caucuses, finished a close second, spinning their race forward to a showdown 11 days from now in Nevada.
In the Republican race, John McCain capped an improbable comeback by marching to victory over Mitt Romney and trouncing the victor in Iowa's caucuses, Mike Huckabee.
Independent voters, free to cast their ballots in either party's contest, made the difference for McCain but failed to push Obama past Clinton. She became the first female candidate ever to win a major-party primary and took a significant step toward becoming the nation's first female president.
Clinton also wrote her own chapter in the storied annals of New Hampshire politics. It was here that Bill Clinton, fighting exhaustion and allegations of womanizing and draft-dodging, rallied to a second-place finish to become the self-proclaimed "comeback kid."
"I felt like we all spoke from our hearts, and I am so gratified that you responded," a beaming Clinton told supporters. "Now together, let's give America the kind of comeback that New Hampshire has just given me."
Thanking New Hampshire for rescuing her campaign, she said, "Over the last week I listened to you, and in the process I found my own voice."
Sen. Clinton's travails -- while less personal than her husband's -- were no less formidable. After finishing third in last week's Iowa caucuses, she faced polls that gave Obama a double-digit New Hampshire lead, and a sense -- even among insiders -- that her campaign was verging on collapse.
Instead, the New York senator got 39% of the vote to 36% for Sen. Obama of Illinois. Former Sen. John Edwards of North Carolina received 17%, and New Mexico Gov. Bill Richardson 5%, with 96% of the precincts reporting.
Speaking to supporters, Obama acknowledged that "the battle ahead will be long," but said that nothing could stand in the way of "millions of voices calling for change."
On the Republican side, the New Hampshire results further scrambled the most unpredictable GOP contest in generations. The race heads to Michigan on Jan. 15, and South Carolina and Nevada on Jan. 19, with no clear front-runner.
Sen. McCain of Arizona had 37% to former Massachusetts Gov. Romney's 32% and former Arkansas Gov. Huckabee's 11%. Former New York Mayor Rudolph W. Giuliani had 9%, and Rep. Ron Paul of Texas had 8%.
"I'm past the age when I can claim the noun 'kid,' no matter what adjective proceeds it," McCain told cheering supporters at his headquarters hotel in Nashua. "But tonight, we sure showed them what a comeback looks like."
Scheduled five days after Iowa voted -- with Christmas lights still winking from some houses -- the New Hampshire primary underscored the rapid-fire nature of this dramatically telescoped nominating season. A month from now, more than half the states -- including California -- will have voted; from here on the campaign becomes a sprint, with the potential for more hairpin turns.
Before polls closed Tuesday, the Clinton campaign had reached out to supporters frazzled by her third-place Iowa finish and Obama's rise in New Hampshire polls.
One fundraiser said aides had sent word around the country that they planned to reexamine every facet of Clinton's operation, with a focus on her frequently shifting message. But as the returns rolled in Tuesday night, pessimism abruptly turned to euphoria. "We're gearing up, not shaking up," said Ann Lewis, a senior Clinton advisor.
Among those set to join the campaign is Doug Sosnik, a former political director and senior advisor in the Clinton White House.
New Hampshire has long hosted the nation's first primary -- giving the tiny state a huge say in picking presidents -- and on Tuesday residents embraced their opportunity with gusto. Turnout was expected to set a record of about 500,000 voters, meaning nearly four in 10 residents went to the polls.
From the beginning, New Hampshire's Democratic primary was a fight between Clinton and Obama. Edwards, who finished second in Iowa, was never a strong factor here.