"I felt like we all spoke from our hearts and I am so gratified that you responded," Clinton said in victory remarks before cheering supporters. "Now together, let's give America the kind of comeback that New Hampshire has just given me."
McCain was also fired up. "We showed this country what a real comeback looks like," the Arizona senator told The Associated Press in an interview as he savored his triumph. "We're going to move on to Michigan and South Carolina and win the nomination."
The close Democratic race resulted in Clinton and Obama each winning nine national convention delegates, with Edwards getting four, according to an AP analysis.
In the overall race for the nomination, Clinton leads with 187 delegates, including separately chosen party and elected officials known as superdelegates. She is followed by Obama with 89 delegates and Edwards with 50.
McCain won seven Republican delegates to four for Romney and one for Huckabee. New Hampshire originally had 24 Republican delegates, but the national party stripped half as punishment because the state broke party rules by scheduling its primary so early.
In the overall race for the GOP nomination, Huckabee leads with 31 delegates, followed by Romney with 19 and McCain with seven.
Obama's defeat came as he won an endorsement from the Nevada chapter of the Service Employees International Union, which represents 17,000 workers in the state that votes next. He is still strong in South Carolina, where the Democratic electorate is heavily black and likely to go for the most viable black presidential candidate in history.
The Republican race turns next to Michigan, where McCain and Romney already are advertising on television, and where both men planned appearances on Wednesday. Huckabee also was expected to campaign in the state.