Senator John McCain of Arizona, whose bid for the Republican presidential nomination was all but dead this summer, has made a dramatic recovery in the Granite State 2 1/2 weeks before the 2008 vote, pulling within 3 percentage points of front-runner Mitt Romney, a new Boston Globe poll indicates.

McCain, the darling of New Hampshire voters in the 2000 primary, has the support of 25 percent of likely Republican voters, compared with 28 percent for Romney. Former New York mayor Rudy Giuliani has slid into third place, with 14 percent. A Globe poll of New Hampshire voters last month had Romney at 32 percent, Giuliani at 20 percent, and McCain at 17 percent.

Among Democratic voters, Senator Barack Obama of Illinois has opened up a narrow lead over Senator Hillary Clinton of New York, 30 percent to 28 percent. That, too, represents a major shift from last month's Globe poll, which had Clinton with a 14-point advantage. Former senator John Edwards of North Carolina remained a steady third at 14 percent.

The Globe poll also found wide disparities in voter opinion on domestic issues, with Republicans and Democrats expressing starkly different views on the government's role in healthcare and on whether illegal immigration is a problem.

The survey provided fresh evidence of how tight the primary contests have become in New Hampshire and around the country, adding to a growing sense among political analysts, voters, and the campaigns that neither party has a clear front-runner just days before the crush of primaries begins.

The survey of 422 likely Democratic voters and 410 likely Republican voters in New Hampshire, conducted from Dec. 16 to Dec. 20, has a margin of error for each party subsample of plus or minus 4.9 percentage points.

The races in New Hampshire are still wide open - roughly 40 percent of likely voters in both parties indicated they are still undecided.

But McCain's momentum is striking given that he was essentially written off by the political class and by rivals after weak fund-raising and excessive early spending forced him to completely retool his campaign in July. Since then, his focus on New Hampshire, stumbles by his opponents, and a series of newspaper endorsements have helped him regain traction.

"Republicans talked about the John McCain deathwatch back in the summer," said Andrew E. Smith, director of the University of New Hampshire Survey Center, which conducted the Globe poll. "He's back to the John McCain of 2000."

McCain appears to have gained ground without a surge of support from independent voters, who propelled him to a double-digit win over George W. Bush in the 2000 primary and nearly catapulted him to the GOP nomination. McCain earned more support in the Globe poll from registered Republicans than from "undeclared" voters.