So-called "sanctuary cities" have come under heavy scrutiny after Kathryn Steinle was fatally shot earlier this month in San Francisco, allegedly by an undocumented immigrant with a long criminal record and multiple deportations.
Democrats dubbed the bill the "Donald Trump Act," and accused Republicans of aligning themselves with the real estate mogul and his anti-immigrant views, Reuters reported.
"The Donald Trump wing of the Republican Party is clearly ascendant here today," Representative Lloyd Doggett, of Texas, said in floor debate. "This bill is not about grabbing criminals; it's about grabbing headlines."
Five Republicans and all but six Democrats voted against the bill.
The law would withhold certain law enforcement grants and funding from jurisdictions that bar the collection of immigration information or refuse to cooperate with federal "detainer" requests.
Republicans, including the bill's sponsor, Representative Duncan Hunter, of California, said such legislation was desperately needed following Steinle's killing.
Representative Trey Gowdy, a South Carolina Republican, called the issue of sanctuary cities something that is "quite literally life and death."
"There are criminals motivated by malice and a conscious disregard for the lives of others, and there are cities more interested in providing a sanctuary for those criminals than they are in providing a sanctuary for their law-abiding citizens," he said.
The White House, meanwhile, threatened a veto, saying the bill fails to offer comprehensive immigration reform.
Juan Francisco Lopez Sanchez has been charged with Steinle's killing. He had been released by San Francisco police despite a request from federal immigration officials to keep him detained.
As for Trump, the Republican presidential candidate spent part of Thursday in Loredo, Texas, a border town whose population is 95% Hispanic. The stop comes a month after he called undocumented Mexican immigrants drug traffickers and rapists.
"I think I'll win the Hispanic vote," Trump said on Thursday. "Over the years, thousands and thousands of Hispanics have worked for me."