On the Republican side, there was also a comeback, with John McCain taking first place.
In one of the most unpredictable and exciting contests for years, Clinton overcame a double-digit deficit in opinion polls to squeeze out a narrow victory over Obama.
With almost all the results in, Clinton had captured 39 per cent of the vote and Obama 37 per cent. John Edwards had 17 per cent.
The significance of the victory, after opinion polls and even Clinton's own advisers expecting defeat, was reflected in an unusually emotional speech from the normally self-contained candidate.
“I come tonight with a very full heart. I want especially to thank New Hampshire. Over the last week I listened to you and found my own voice. I want to give America the kind of comeback New Hampshire has given me,” she said.
The decisive moment for Clinton appeared to be an encounter in a diner on Monday, in which she came close to tears when talking about the campaign.
The clip, which was shown repeatedly on television, revealed a rare vulnerability.
The tight race was all the more resonant because of the Clintons' history in New Hampshire. In 1992, Bill Clinton used his surprising second place finish as a springboard to the nomination calling himself the Comeback Kid.
“This is a huge victory for Hillary. We have stopped the freight train,” a Clinton insider said.
Minutes before Clinton made her victory speech, Obama conceded victory and congratulated Clinton. But he said he was stilled “fired up and ready to go” and that he remained the candidate for change.
Republican race
In the Republican race, McCain celebrated his victory with supporters. “We sure showed the people of this country what a real comeback looks like. We're going to move on to Michigan and South Carolina and win the nomination,” he said.
He ran even with Romney among Republicans voters and owes his success to the overwhelming support of independents.
McCain's win leaves the Republicans with no clear frontrunner.