Mrs Clinton had trailed in opinion polls going into the vote
Democratic White House hopeful Hillary Clinton defied pundits and pollsters by winning New Hampshire's primary, beating rival Barack Obama.
John McCain made his own remarkable political comeback with a convincing win in the Republican contest.
Observers say it seems to have been a record-breaking turnout, with some half a million people having cast ballots.
Candidates are aiming to build momentum before more than 20 states hold polls on 5 February, known as Super Tuesday.
New York Senator Clinton, 60, told a cheering crowd of supporters: "Over the last week I listened to you and in the process I found my own voice. I felt like we all spoke from our hearts and I am so gratified that you responded."
She echoed her husband, former President Bill Clinton, who in New Hampshire's primary in 1992 called himself the "comeback kid" when his own White House bid was resurrected by a strong, second place finish in the state.
Hillary Clinton - 39%
Barack Obama - 36%
John Edwards - 17%
Bill Richardson - 5%
Source: Associated Press
Analysis: Clinton's surprise?
In pictures: N Hampshire vote
The BBC's Justin Webb, reporting from Mrs Clinton's celebration rally, says she not only repeated her husband's feat but perhaps improved on it, because the opinion polls, the Obama team and the media had indicated strongly that victory was his.
Polling station interviews suggested registered Democrats and female voters, who deserted Mrs Clinton last week in Iowa, helped sweep her to victory, overcoming Senator Obama's advantage among New Hampshire's independent voters.
Mr Obama said: "I want to congratulate Senator Clinton on a hard fought victory here in New Hampshire. She did an outstanding job, give her a big round of applause."
He had gone into the vote with leads of up to 13 points in opinion polls following his impressive victory in Thursday's Iowa caucuses, after trailing Mrs Clinton for much of the campaign.
McCain supporters chanted "Mac is back, Mac is back".
McCain victory speech
The BBC's Kevin Connolly in New Hampshire says Mrs Clinton's win may be down to an extraordinary moment on Monday when she appeared close to tears as she talked about how much public service meant to her.
John Edwards, who came third in the Democrat contest, reminded supporters in Manchester, New Hampshire, that there were "48 states left to go".
In the Republican race, Arizona Senator McCain rode to victory, taking 37% of the vote to defeat former Massachusetts governor Mitt Romney into second place with 32%.
The 71-year-old former Vietnam prisoner of war's triumph put him firmly back in contention for the White House, said correspondents.
John McCain - 37%
Mitt Romney - 32%
Mike Huckabee - 11%
Rudy Giuliani - 9%
Ron Paul - 8%
Mr McCain used to be the front-runner but his campaign crumbled last year when his funds and support evaporated, analysts said, down to his unflinching support for the Iraq war.
At his campaign headquarters, Mr McCain thanked his supporters, saying: "My friends, you know I'm passed the age where I can claim the noun 'kid', no matter what adjective precedes it. But tonight we sure showed 'em what a comeback looks like."
Former Massachusetts governor Mr Romney congratulated Mr McCain and said: "Well another silver... I'd rather have a gold, but I got another silver.
Former Arkansas governor and Baptist minister Mike Huckabee and former New York mayor Rudy Giuliani came in with 11% and 9% of the vote for the Republicans, according to ABC projections.
KEY DATES AHEAD
15 Jan: Michigan primary
19 Jan: Nevada caucuses; South Carolina primary (Rep)
26 Jan: South Carolina primary (Dem)
29 Jan: Florida primary
5 Feb: some 20 states including California, New York, New Jersey
Q&A: US primaries
Mr Giuliani said he planned to stay in the race and was looking forward to Florida's 29 January primary.
The BBC's James Coomarasamy in New Hampshire says a wounded Mr Romney must now bounce back from his Iowa and New Hampshire defeats, states where he far outspent his opponents.
Mr Huckabee, by contrast, will take heart from his third place finish in a state where he was never expected to do well, our correspondent says.
The election battle now gathers pace, with Michigan holding its primary next Tuesday and Nevada its caucuses on 19 January.
And the next big contests are set for South Carolina, where Republicans hold their primary on 19 January with the Democrats in the state making their choice a week later on 26 January.
Analysts say South Carolina's large bloc of black Democratic voters are likely to go for Mr Obama, who aims to become the first black US president.