MANCHESTER, N.H. - Arizona Sen. John McCain, near broke and far behind several months ago, won Tuesday's New Hampshire Republican primary and climbed back into the race for his party's presidential nomination as he headed to upcoming contests that could be tougher battles for him.

"Mac is back. Mac is back," McCain supporters chanted as the victory became clear.

Yes, he said, he is. "We showed the people of this country what a real comeback looks like," he said before addressing supporters. "We're going to move on to Michigan and South Carolina and win the nomination."

McCain had a 5 percentage-point lead over Mitt Romney, the former governor of next-door Massachusetts and owner of a New Hampshire vacation home. Former Arkansas Gov. Mike Huckabee, last week's winner in Iowa, was a distant third.

"Who'd have thought it last summer?" said Dartmouth political scientist Linda Fowler. She still sees McCain facing major challenges in getting the nomination.

The GOP race, she said, is "wild and woolly" and could remain so until Feb. 5, when a long list of states have primaries.

The New Hampshire race largely was a McCain-Romney battle, with Huckabee, a former Arkansas governor, acknowledging that the lack of evangelical voters made him a long shot. Exit polls showed that 29 percent of GOP voters identified themselves as evangelicals. In Iowa, it was 60 percent.

Former New York Mayor Rudy Giuliani largely skipped New Hampshire and stuck with a strategy keyed on later races.

McCain won despite exit polls showing more independents, free to vote in either contest, voted in the Democratic primary. His 2000 win in New Hampshire was fueled heavily by independents, many of whom were attracted this year by Democrat Barack Obama.

Staffers and volunteers exchanged high fives and waved their fists.

McCain's win was crucial for his candidacy and Romney's second-place finish was damaging, coming in his back yard and in a state where he spent a fortune on ads and in the wake of the Iowa loss to Huckabee. But the Republican race could be headed for another reshuffling in the next major battles, in Michigan next Tuesday and South Carolina on Jan. 19.

Romney told boisterous supporters that he will campaign on and plans to win the nomination.

And in words that carried two meanings, Romney, who had counted on a win there and had more than 250 events in the state, thanked New Hampshire residents by saying, "We thought we knew New Hampshire, but now we really know New Hampshire."

A victory speech

Giuliani spoke to supporters in the state and then headed for Florida. "This is just the beginning. Think of it as the kickoff in what's going to be a very long and very tough game," Giuliani said. "By the time it's over with, by February 5th, it's going to be clear that we're the nominee of the party."

Third-place finisher Huckabee gave a victory speech, telling supporters he had done better than anyone thought "this old unknown Southern boy could possibly do up here in New England."

"Frankly, I'm not sure what all some of you did that I don't even want to know, but thank you for getting it done because tonight we come out of here with continued momentum," said Huckabee, recalling he had thought a fourth- or fifth-place finish would be OK.

Campaign gets off track

Once considered the favorite in a multi-candidate field, McCain capsized last year, his campaign plummeting as he defended a plan to give illegal immigrants an eventual path to citizenship, angering a GOP conservative base that had never fully trusted the maverick senator, especially after he broke with President Bush on tax cuts. A raft of senior aides abandoned ship and more were laid off as McCain ran out of money.

Then, a confluence of events helped to stabilize McCain. Support began to slowly but steadily erode for Giuliani, who attracts the same independent-minded Republicans as McCain.

Former Tennessee Sen. Fred Thompson faded after his late entry into the race. Huckabee surged in Iowa, pulling conservatives from Romney, whose Mormonism drew suspicion from the party's evangelical Christian base.

Shooting ahead

The immigration drumbeat began to subside as attention turned to other issues, and the unpopular war in Iraq seemed to be turning around, a development Republicans credited to Bush's troop surge, a strategy long advocated by McCain.

In recent weeks, McCain shot ahead of Giuliani and finally Romney in polls in New Hampshire.

McCain won Michigan in 2000, his last major win over eventual nominee George W. Bush. But this year's primary in the economically troubled state will be something of a home game for Romney, raised there as the son of the late George Romney, a former governor and auto executive.

This year's Michigan race will be the first in which McCain, Romney and Huckabee all are making significant effort, though Giuliani continues to look forward to Florida on Jan. 29 and the long list of states with Feb. 5 contests.

The Associated Press contributed to this report.