Footage of agents patrolling the rocky, arid Southwestern landscape is featured in Mr. Brown’s ads — not quite the piney highlands of New Hampshire.

Image Scott P. Brown is using illegal immigration as an issue in his Senate campaign in New Hampshire, which has one of the smallest populations of illegal immigrants in the country. Credit... Jim Cole/Associated Press

A political group led by prominent conservatives like John R. Bolton, the former United States ambassador to the United Nations, attacked Ms. Shaheen last week with a video that juxtaposed two alarming images: a horde of people rushing a fence, presumably along the Mexican border, and a clip of Islamic militants right before they beheaded the journalist James Foley, a New Hampshire native. The ad was pulled after the Foley family complained.

Republicans have long relied on illegal immigration to rally the conservative base, even if the threat seemed more theoretical than tangible in most of the country. But in several of this year’s midterm Senate campaigns — including Arkansas and Kansas, as well as New Hampshire — Republicans’ stance on immigration is posing difficult questions about what the party wants to be in the longer term.

Some Republicans are questioning the cost of their focus on immigration. Campaigning on possible threats from undocumented immigrants — similar to claims that President Obama and the Democrats have left the country vulnerable to attacks from Islamic terrorists and the Ebola virus — may backfire after November. At that point, the party will have to start worrying about its appeal beyond the conservative voters it needs to turn out in midterm elections.

“You should never underestimate the ability of the Republicans to screw something up and blow an ideal opportunity,” said Ralph Reed, an influential conservative who has battled with hard-line Republicans to take a more charitable view on immigration.