The House on Thursday passed legislation that would deny millions of dollars in federal funding to "sanctuary cities" that defy federal immigration laws.

Lawmakers voted 241 to 179 in favor of the "Enforce the law for Sanctuary Cities Act," a measure that was first introduced in 2011 but gained momentum after the shooting death of 32-year-old Kate Steinle in San Francisco by an illegal immigrant local authorities refused to detain despite federal orders. The bill passed in a mostly partisan vote, although six Democrats voted for it, and five Republicans voted against it.

The bill was introduced by Rep. Duncan Hunter, R-Calif., and would withhold key federal law enforcement grants to "sanctuary cities," that shield illegal immigrants from deportation.

Steinle's shooter, Juan Francisco Lopez-Sanchez, was a convicted felon who had been deported five times. City officials said they lacked a federal arrest warrant needed to keep Lopez-Sanchez in jail.

Lawmakers in favor of the bill said it is time for the federal government to act against cities that refuse to abide by federal immigration laws.

"It helps to address one of the main factors contributing to the collapse of immigration enforcement in the United States: sanctuary cities that prohibit their law enforcement officers from sharing information with federal immigration authorities to enable the removal of unlawful and criminal aliens," said House Judiciary Committee Chairman Bob Goodlatte, R-Va.

But most Democrats were staunchly opposed to the legislation, saying it will cut off critical funding to major cities, including Los Angeles, which adheres to sanctuary city policies.

"This bill," said Rep. Xavier Becerra, D-Calif., "punishes police that had nothing to do" with releasing the man who shot Steinle.

Becerra said San Francisco authorities had "dropped the ball," in releasing Lopez-Sanchez from jail.

The bill passed after Steinle's father delivered emotional testimony at separate House and Senate hearings this week. House Majority Leader Kevin McCarthy, R-Calif., called the legislation, "a good first start."

Earlier in the day, President Obama threatened to veto the legislation.

"This bill fails to offer comprehensive reforms needed to fix the nation's broken immigration laws, undermines current administration efforts to remove the most dangerous convicted criminals and to work collaboratively with state and local law enforcement agencies, and threatens the civil rights of all Americans by authorizing state and local officials to collect information regarding any private citizen's immigration status, at any time, for any reason, and without justification," the Office of Management and Budget said in a statement of administration policy issued Thursday morning.