By Laura Smith-Spark
BBC News, New Hampshire
It was the tale of two comebacks.
Republican Senator John McCain's presidential campaign was all but written off last summer.
But buoyed by recent opinion polls, Mr McCain returned to the scene of his greatest previous political triumph - his 2000 New Hampshire primary victory over George W Bush - to take the Republican spoils.
And if Mr McCain's comeback was remarkable, Democrat Hillary Clinton's win was a spectacular turnaround, confounding the polls and the pundits alike.
Trailing third last week in Iowa, her performance in New Hampshire was billed as make or break for her campaign.
Early analysis of the polling data - after a record turnout - suggests that Senator Clinton's success over Barack Obama may be partly down to the fact she did much better among women voters than she did in Iowa.
She will also have benefited from her long association with a state where her husband, the former President Bill Clinton, earned the title the "comeback kid" in 1992.
Earlier on polling day, Mrs Clinton, accompanied by daughter Chelsea, received something of a rock star welcome as she stopped by a polling station at Broken Ground School in Concord.
Among the crowd waiting to greet her were dozens of excited school children, eager to meet the former First Lady after spending a week learning about the primary process.
Mrs Clinton, showing no sign of repeating the much-commented on display of emotion of a day earlier, seemed cheerful as she joked and posed for photos with them.
Her supporters lined the entrance to the school with banners and "Hillary for President" T-shirts.
Clutching a huge sign was campaign volunteer Nancy Kanniainen, a recently retired occupational therapist, who said she was very excited to meet Mrs Clinton.
"We've been working for her for the last four weeks here. I also helped to elect her senator in upstate New York where I live.
"We're in this all the way - we are here to see her president. I'm in it all the way to November."
Eighteen-year-old volunteer Grady Keefe, from Connecticut, was also optimistic - a sentiment that turned out to be well-founded.
"I wouldn't be standing here if I thought she was going to lose. I'd be on the next train home," he said.
"What's really exciting is seeing all these kids taking part for Clinton and Obama and Edwards and, for the first time, exercising their vote and changing the way things happen."
Mr McCain also took the opportunity to hail his own "comeback" but acknowledged that at 71 years of age he couldn't really term himself a "kid".
The former prisoner of war in Vietnam was for many months the Republican front runner but his campaign stuttered badly last year when his fundraising dried up and his support wavered.
With his resurgence in the opinion polls borne out by the results, Mr McCain took care to thank all those who had worked so hard on his behalf. And he had these words for voters:
"I talked to the people of New Hampshire, I reasoned with you, I listened to you, I answered you, sometimes I argued with you, but I always told you the truth as best I can see the truth, and you did me the great honour of listening. Thank you, New Hampshire."
His victory over Mitt Romney who finished second and last week's Iowa victor Mike Huckabee who was third heats up the battle for the Republican nomination.
For Senator Obama's supporters, it was not the post-primary party they had been expecting.
Hundreds had waited outside Nashua High School after the close of voting to take part in what most assumed would be a victory rally.
After all, just five days earlier the Illinois senator had beaten John Edwards and Hillary Clinton into second and third place - and the latest polls suggested he was about to repeat the feat.
New Hampshire was a surprise setback for Obama's campaign
But, as the early results played on a giant screen inside the gym persistently gave Mrs Clinton a slim lead, the ebullient mood of the crowd became increasingly subdued.
While cheers greeted each slight improvement in the projected results for Mr Obama, as the hours passed it became clear that, despite his recent double-digit lead in the polls, Mrs Clinton had won.
A rousing speech by Mr Obama, who finally sprang on to the stage accompanied by wife Michelle, went some way to bolster the spirits of volunteers weary after hard graft on the campaign trail.
"Nothing can stand in the way of millions of voices calling for change," he said.
And outside, supporters sporting Obama T-shirts and badges and still clutching placards with the slogans "stand for change" and "change we can believe in" remained defiant.
Next week, the primary cavalcade will roll on to Michigan, where only the Republican candidates will compete, to be followed by votes in Nevada and South Carolina.
"New Hampshire voters turned this thing on its ear and said
this is going to be a long race," John Edwards told CNN - a comment that applies equally to both the Democratic and Republican races.