(Charles Dharapak ~ Associated Press)
Clinton's victory capped a comeback from last week's third-place finish in the Iowa caucuses and raised the possibility of a long battle for the party nomination between the most viable black candidate in history and the former first lady, who is seeking to become the first woman to occupy the Oval Office.
McCain's triumph scrambled the Republican race as well.
"We showed this country what a real comeback looks like," the Arizona senator said as he savored his triumph. "We're going to move on to Michigan and South Carolina and win the nomination."
Later, he told cheering supporters that together, "we have taken a step, but only a first step toward repairing the broken politics of the past and restoring the trust of the American people in their government."
McCain rode a wave of support from independent voters to defeat former Gov. Mitt Romney of Massachusetts, a showing that reprised the senator's victory in the traditional first-in-the-nation primary in 2000.
It was a bitter blow for Romney, who spent millions of dollars of his own money in hopes of winning the kickoff Iowa caucuses and the first primary -- and finished second in both. Even so, the businessman-turned politician said he would meet McCain next week in the Michigan primary, and he cast himself as just what the country needed to fix Washington. "I don't care who gets the credit, Republican or Democrat. I've got no scores to settle," he told supporters.
After Iowa, Clinton and her aides seemed resigned to a second straight setback. But polling place interviews showed that female voters -- who deserted her last week -- were solidly in her column in New Hampshire.
She also was winning handily among registered Democrats. Obama led her by an even larger margin among independents, but he suffered from a falloff in turnout among young voters compared with Iowa.
Word of Clinton's triumph set off a raucous celebration among supporters at a hotel in Nashua -- gathered there to celebrate a first-in-the-nation primary every bit as surprising as the one 16 years ago that allowed a young Bill Clinton to proclaim himself "the comeback kid."
She had 39 percent of the vote in the Democratic primary to 37 percent for Obama, who is seeking to become the nation's first black president. Former senator John Edwards of North Carolina trailed with 17 percent. New Mexico Gov. Bill Richardson was fourth, polling less than 5 percent of the vote.
Despite running a distant third to his better-funded rivals, Edwards had no plans to step aside. He pointed toward the South Carolina primary on Jan. 26, hoping to prevail in the state where he was born -- and where he claimed his only victory in the presidential primaries four years ago.
Among Republicans, former Arkansas Gov. Mike Huckabee, who won the leadoff Iowa GOP caucuses last week, was running third in New Hampshire.
McCain was winning 37 percent of the Republican vote, Romney had 32 and Huckabee 11. Former New York Mayor Rudy Giuliani had 9 percent, Texas Rep. Ron Paul 8.