Before the calendar turned to 2016, terrorism overtook the economy as the public's biggest concern for the first time in a decade. The effect of the Paris attacks and the San Bernardino, Calif., massacre on the presidential race was almost immediate.

Gallup found that a higher percentage of Americans were worried about terrorism than mass shootings, a data point that is sure to have an impact on the general election. The Democrats' immediate reaction to San Bernardino, for example, was to call for more gun control. Among Republicans, there was a noticeable shift away from candidates who couldn't pass what GOP strategists called the "commander in chief test."

Retired neurosurgeon Ben Carson slipped from first place in Iowa in October, before the recent terror attacks, to a distant fourth place in January. A CNN/ORC poll pegged his support in the first-in-the-nation caucus state at just 6 percent. Businesswoman Carly Fiorina dropped from double digits in September to as little as 1 percent nationally.

The third major Republican presidential candidate with no governing or foreign-policy experience, Donald Trump, has been an exception to this trend. While the others saw their poll numbers dive, he has thrived, in some cases building on an already comfortable lead nationwide and in the early states.

One reason: immigration. "The key to understanding the contest for the Republican nomination is immigration," wrote Mitt Romney adviser Eric Fehrnstrom. "Once you have the key, you can unlock all the mysteries of the race."

"The key to understanding the contest for the Republican nomination is immigration," wrote Mitt Romney adviser Eric Fehrnstrom. "Once you have the key, you can unlock all the mysteries of the race." (AP Photo)

After a married couple committed to radical Islam, one an immigrant and the other the son of immigrants, murdered 14 people and seriously injured another 22 in San Bernardino, Trump called for restrictions on Muslim immigration, even a temporary ban on foreign Muslim entry into the United States. "We have to get to the bottom of it," Trump said.

Democrats, the media and even leading Republicans were aghast. House Speaker Paul Ryan made a rare public intervention in the presidential race to disassociate the party from Trump's proposals. "This is not conservatism," Ryan said. But the polls showed rank-and-file Republicans and self-described conservatives were more receptive to the idea.

That's not all the polls showed. A December Quinnipiac survey showed Marco Rubio winning a plurality of Republicans who said that foreign policy is their most important issue, although Trump and Ted Cruz were not far behind him. That's understandable: The Florida senator's foreign policy views arguably most closely resemble those implemented by the last Republican president, George W. Bush, after the Sept. 11, 2001, terrorist attacks on the United States.

Yet Trump actually won a plurality of Republicans who listed terrorism as their most important issue, finishing ahead of Rubio by 11 points. It's one of a number of indications that for some Republicans, terrorism is now an immigration-related issue as much or than a foreign policy issue.

"Why are Republicans talking about starting a war in Syria to stop Muslim immigrants from killing Americans in America?" asked the conservative columnist Ann Coulter, who has emerged as one of Trump's most indefatigable defenders. (Some, like journalist David Frum, say her restrictionist book Adios, America influenced Trump's current immigration position.) "Is it our job to straighten out Syria? Can't our government just stop bringing the terrorists here?"

Immigration was a hotly debated issue in the aftermath of 9/11. In 2002, the conservative columnist Michelle Malkin published a New York Times best-selling book titled Invasion: How America Still Welcomes Terrorists, Criminals and Other Foreign Menaces to Our Shores, arguing that porous borders and lax enforcement were a national security issue.

National Review ran a cover story reporting that the visa applications for 15 of the 19 9/11 hijackers should have been rejected. "The forms are incomplete and often incomprehensible — yet that didn't stop any of the 15 terrorists for whom the visa applications were obtained from coming to the United States," ABC News also reported, noting "none of the 15 applications reviewed were filled out properly."

But the consensus, especially among conservatives, quickly became that the best way to avoid terrorism at home was to fight would-be terrorists abroad. Leading Republicans, such as President Bush and John McCain, combined a robust global war on terror with advocacy for comprehensive immigration reforms that would have increased the number of immigrants admitted to the United States.

Mark Krikorian, executive director of the Center for Immigration Studies, which favors lower immigration levels and tighter enforcement, wonders if the nature of attacks like San Bernadino has changed the conversation. He notes the proximity of these events to the murder of Kate Steinle by illegal immigrants in a "sanctuary city," which highlighted immigration enforcement noncooperation in many jurisdictions and was also an issue seized on by Trump.

"The regular crime part and the national security aspects are bleeding into each other," Krikorian told the Washington Examiner. "They are unrelated but they are feeding off each other." He said that connection is stronger in Europe, where immigrants with jihadi sympathies are often "jailbirds" engaged in crimes unrelated to terrorism.

Virtually the entire GOP presidential field has argued against resettling Syrian refugees in the United States on national security grounds. (AP Photo)

The relatively recent immigrant background of some of the people involved in the most high-profile incidents, such as the perpetrators of the Boston Marathon bombings, has also raised concerns that immigration is making homegrown jihadist problems worse. Then there is the deliberate exploitation of the system by terror groups.

"Foreign-born militant Islamic terrorists have used almost every conceivable means of entering the country. They have come as students, tourists and business visitors," wrote the Center for Immigration Studies' Steven Camarota. "They have also been Lawful Permanent Residents (LPRs) and naturalized U.S. citizens. They have snuck across the border illegally, arrived as stowaways on ships, used false passports and have been granted amnesty. Terrorists have even used America's humanitarian tradition of welcoming those seeking asylum."

Tom Tancredo and J.D. Hayworth, then-sitting Republican members of Congress, each published books making these arguments 10 years ago. The books were popular, but Tancredo failed to gain any traction when he ran for president in 2008, the year John McCain won the GOP presidential nomination. McCain beat Hayworth two years later in Arizona's Republican senatorial primary. Both defeats convinced many Republicans that immigration politics was a dead end. But Tancredo, who has endorsed Ted Cruz for president and urged Trump to be "a little bit more artful" when discussing immigration, thinks this campaign will change that perception.

Republican presidential candidates with very different immigration sympathies than Trump seem to think so. Virtually the entire GOP presidential field, including longtime comprehensive reform champions Jeb Bush and Chris Christie, have argued against resettling Syrian refugees in the United States on national security grounds. Christie said he wouldn't even make an exception for "orphans under age five."

"I do not trust this administration to effectively vet the people who are supposed to be coming in in order to protect the safety and security of the American people, so I would not permit them in," the New Jersey governor told conservative radio show host Hugh Hewitt. Cruz made a pithier version of this argument in a primary debate, saying, "Border security is national security and we will not be admitting jihadists as refugees."

Cruz said lawmakers like himself "chose to stand with [immigration hawk members of Congress] Jeff Sessions and Steve King and the American people and secure the border," adding "the front line with ISIS isn't just in Iraq and Syria, it's in Kennedy Airport and the Rio Grande."

The Texas senator then lit into Rubio for the 2013 Gang of Eight immigration reform bill. Speaking in the same debate, so did Rand Paul. "He thinks he wants to be this, 'Oh I am great and strong on national defense,' but he is the weakest of all the candidates on immigration," the Kentucky senator said. "He is the one for an open border leaving us defenseless."

Most striking has been how Rubio has reacted to immigration as a national security issue becoming a political liability for his 2016 campaign. In January, when he was asked one of the most pointed questions he has faced from a debate moderator about the impact of immigration on American workers, he immediately pivoted to counterterrorism.

Rubio replied that immigration and the legal status of the undocumented population has "been debated now for 30 years." He continued, "This issue isn't about that anymore." He contended the situation has changed even since he advocated Gang of Eight.

"First and foremost, this issue has to be now more than anything else about keeping America safe," he said. "And here's why. There is a radical jihadist group that is manipulating our immigration system. And not just green cards. They're looking, they're recruiting people that enter this country as doctors and engineers and even fiancees. They understand the vulnerabilities we have on the southern border."

Trump actually won a plurality of Republicans who listed terrorism as their most important issue, finishing ahead of Rubio by 11 points. (AP Photo)

"So our number one priority must now become ensuring that ISIS cannot get killers into the United States," Rubio concluded. "So whether it's green cards or any other form of entry into America, when I'm president if we do not know who you are or why you are coming, you are not going to get into the United States of America."

This answer has several benefits. It helps him explain an apparent flip-flop on Gang of Eight. It beefs up the national security credentials his immigration position threatens to erode. And it shows he is thinking about immigration and terrorism the way a growing number of Republicans, and most of his critics within the party, have come to view it.

All this is annoying both to Republicans who think Rubio gets a free pass on Gang of Eight as well as his former comprehensive reform partners who had hoped the Floridian would transform GOP thinking on immigration into something more welcoming and less fearful.

But in an era where Trump is most trusted on terror, it is hard to argue with the politics.