WASHINGTON — Illegal immigration, the top issue on the minds of Iowa Republicans a week ago, receded significantly as an issue in New Hampshire, helping immigration reform champion John McCain coast to victory on Tuesday.

The Arizona senator took advantage of the shifting sands of public opinion by winning the overwhelming support of Republicans who do not see illegal immigration as a threat. Former Massachusetts Gov. Mitt Romney was the choice of Republicans who would crack down on those illegally in the U.S.

In the closing days of the New Hampshire campaign, Romney aired TV attack ads criticizing McCain for advocating "amnesty" for illegal immigrants. But independent New Hampshire pollster Dick Bennett said that the commercials backfired on Romney.

"The voters punished him for doing it because they don't like the negative stuff and he was the only one doing it," Bennett said.

McCain, in his victory speech, suggested that he benefited by standing firm on an issue that has angered many in his party's conservative base.

"I didn't tell you what the polls told me you wanted to hear," he told the crowd.

According to CNN exit polls, immigration was the least important issue to McCain supporters. Among Romney supporters, illegal immigration was their top concern, far ahead of the economy and terrorism.

In Iowa, 33 percent of Republicans cited illegal immigration as the most important matter facing the country, according to CNN entrance polls. But that slipped to 22 percent in New Hampshire, placing it third behind the economy and Iraq war.

New Hampshire Republicans were far more concerned about the sputtering U.S. economy, and that helped McCain, who has earned a reputation as a budget hawk and immigration moderate in Washington.