The Republican-led House on Thursday narrowly defeated an attempt to bar young immigrants living in the country illegally to enlist in the armed forces, as opponents tied the measure to Donald Trump's presidential campaign.

Lawmakers voted 211-210 to reject an amendment by Rep. Paul Gosar, R-Ariz., to the annual defense spending bill. He said he wanted to close what he called a "backdoor amnesty program" created by President Barack Obama without approval from Congress.

Rep. Ruben Gallego, D-Ariz., linked Gosar's amendment to Trump's characterizations of immigrants and the candidate's proposals to deport those illegally in the United States. Trump also wants to build a wall along the Mexican border.

"I am glad to see that some Republicans are rejecting the tired, anti-immigrant policies promoted by the likes of Donald Trump," Gallego, a former Marine who served in Iraq, said.

The potential recruits were brought to the U.S. illegally as children. They are protected from deportation under the Obama administration's Deferred Action for Childhood Arrivals program, or DACA. They also receive temporary work permits, renewable every two years as long as they meet certain requirements. Federal officials have said the program is not a pathway to permanent residency or citizenship.

More On This...

The Pentagon announced nearly two years ago that DACA beneficiaries would be allowed to enlist in a trial program that had been open only to legal immigrants who had unique language, medical and cultural skills.

Gallego said weeks ago the House Armed Services Committee approved a compromise that affirmed the secretary of defense's authority to allow any immigrant to enlist, including DACA beneficiaries, if it's determined to be in the national interest.

Gosar said the Pentagon told him that 141 DACA immigrants have used that path to join the military. But the program was never supposed "to be utilized for the benefit of illegal aliens," according to Gosar, who said they can be granted citizenship if they are deployed to a combat zone for at least one day. He said his amendment would have returned the program to its original intent.

"The president has relentlessly amended immigration law by executive fiat and executive edict. And this is another time," said Rep. Steve King, R-Iowa, a frequent critic of the Obama administration's immigration policies who supported Gosar's proposal.

A separate but similar amendment to Gosar's by King would have blocked the Pentagon from using any money to enlist DACA beneficiaries. It failed on a vote of 214-207.

Gallego also opposed King's amendment. "Your patriotism is more important than your papers," he said.

Following the votes on the immigration amendments, the House decisively passed the $575.7 billion defense spending bill, 282-138.

The White House threatened Tuesday to veto the bill, which maintains a ban on moving prisoners held at the Guantanamo Bay, Cuba, detention facility to the United States. It also denies the use of any money for the construction or modification of a facility in the U.S. to replace the prison at Guantanamo.

The prohibition, which has been included in prior defense bills, has prevented Obama from fulfilling a campaign pledge to shutter the facility.

The Pentagon's request for a new round of military base closures is denied, according to the bill.

The legislation also continues a strategy for boosting the Pentagon's budget by billions of dollars that the Obama administration has condemned as a gimmick.

The bill shifts nearly $16 billion from the account for wartime operations to pay for more weapons, troops and maintenance, a move the Pentagon has sharply criticized as gambling with money needed to support troops in combat. It mirrors an approach taken by the House last month when it passed the annual defense policy bill, which authorizes spending for the military.

Republicans have said the increase in spending is badly needed to halt a decline in the combat readiness of the armed forces. They expect the war account will be replenished early next year by the new president.

But the White House veto threat warned that adding more money for defense could create more problems than it solves unless there are corresponding increases in subsequent years. The funding approach advocated by the House invites "a significant, unacceptable risk of creating a future hollow force, in which force structure exists, but the resources to make it ready do not follow," according to the White House statement.