The House approved legislation Thursday to punish so-called “sanctuary cities” for failing to cooperate with federal immigration authorities, in the first congressional response to a brazen murder earlier this month in San Francisco allegedly committed by an illegal immigrant.  

The bill, sponsored by Rep. Duncan Hunter, R-Calif., would penalize jurisdictions that bar the collection of immigration information or don't cooperate with federal “detainer” requests, by blocking them from receiving certain federal law enforcement grants and funding.

It passed 241-179. The Senate is considering similar legislation. 

“Sanctuary city policies needlessly endanger American lives by refusing to honor the federal government’s authority to enforce immigration laws,” House Judiciary Committee Chairman Bob Goodlatte, R-Va., said in a statement. “Unfortunately, the Obama Administration’s own foolish policies enable rogue local governments to defy federal immigration laws. All too often, these reckless policies create preventable tragedies.”

The legislation already faces a White House veto threat. The White House said the bill “fails to offer” comprehensive reforms and undermines current efforts to remove dangerous convicted criminals and work with local law enforcement.

Angry Democrats accused Republicans of aligning themselves with Donald Trump and his brash anti-illegal immigrant views.

The legislation is the first passed since the July 1 killing of Kathryn Steinle on a California pier.

Steinle, 32, was allegedly shot by Juan Francisco Lopez Sanchez, an illegal immigrant who had been released from city sheriff’s department custody in April.

According to federal immigration officials, Sanchez had already been deported five times and had a lengthy felony criminal record. After serving most of his recent sentence, federal officials turned him over to San Francisco in March on an outstanding warrant – and the city released him weeks later without notifying the feds.

The city argued it had no grounds on which to hold him.

Steinle’s case sparked a fresh round of debate about local jurisdictions – the so-called sanctuary cities – that don’t cooperate with federal immigration authorities in order to protect those legally living in the U.S. Steinle’s father Jim testified this week on Capitol Hill in support of changes to the law.

"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," Rep. Trey Gowdy, R-S.C., said. "This is more than an academic discussion. ... It is quite literally life and death."

But Rep. Lloyd Doggett, D-Texas, said the bill was “not about grabbing criminals” but about “grabbing headlines.”

Members of both parties endorsed Steinle's plea but offered different diagnoses of the problem, with Republicans calling for more enforcement of the law and Democrats calling for a comprehensive immigration overhaul, something House Republicans have blocked for years.

The comments echoed the years-long national debate over immigration, but this latest chapter comes at a moment when immigration has become a hot-button issue on the presidential campaign trail, thanks to Trump's provocative claims about Mexican immigrants being "rapists" and "criminals."

Trump traveled to the U.S.-Mexico border on Thursday to continue his focus on the issue, to the dismay of many Republicans who fear his campaign risks further alienating Latino voters from the Republican Party. House Republicans rejected Democratic attempts to connect their legislation with Trump's campaign.

"We have a horrible tragedy that was preventable," said Speaker John Boehner, R-Ohio, when asked about the link. "Cities do not have the right to ignore federal laws that require them to incarcerate people who have committed serious felonies."

Not all House Republicans were backing the bill. Rep. Carlos Curbelo, R-Fla., a supporter of a comprehensive overhaul, said Thursday's bill wouldn't have prevented Kathryn Steinle's death to begin with.

"This is an exercise, this is not a solution," Curbelo told reporters. "This may generate a headline, but it's not going to solve a problem."

But other House Republicans viewed Thursday's vote as just the first step in advancing a slate of enforcement-focused immigration bills centered on beefing up border security and cracking down on immigrants with criminal records. Such an approach would ignore the advice of some Republican Party leaders who've urged the party to reach out to Latino voters by embracing comprehensive overhaul legislation including a path to citizenship for the 11.5 million people in the country illegally.

"The appetite for amnesty has diminished dramatically after we see the carnage in the streets of America at the hands of criminal aliens that should have been removed from the country," said Rep. Steve King, R-Iowa. "And so that means that now the climate is much better to try to move down the line on enforcement."

The Associated Press contributed to this report.