Senate Democrats on Tuesday blocked a Republican-backed bill that would crack down on so-called sanctuary cities by threatening to withhold funds to local governments that don't cooperate with federal immigration officials. 

The bill failed on a 54-45 vote. It needed 60 to advance. 

The Stop Sanctuary Cities Act became a lightning rod issue ahead of the vote, as GOP sponsors tried to peel off just a few Democrats to support it while Democratic leaders blasted the legislation as counterproductive. The White House issued a formal veto threat Tuesday morning, while the chamber's top Democrat tried to discredit the measure by calling it "The Donald Trump Act." 

But GOP backers cast the legislation as a critical first step toward reining in the exploding, and risky, practice of cities and counties ignoring federal immigration law. 

"Sanctuary cities and the associated violent crimes by illegal immigrants are reaching a critical point, and we cannot wait any longer to take action to protect Americans here at home," sponsor Sen. David Vitter, R-La., said in a statement. 

The bill was considered months after a young woman's murder in San Francisco allegedly at the hands of an illegal immigrant touched off a national debate over immigration law. 

Vitter had urged colleagues to "remember Kate Steinle's vicious murder and the tens of thousands of crimes committed by illegal immigrants within our borders." 

Steinle, 32, was killed July 1 while walking with her dad along a San Francisco pier. The suspect, Juan Francisco Lopez-Sanchez, had a felony record and had been deported five times -- but despite a federal immigration detainer request, the city sheriff released him once an old marijuana charge was dropped. San Francisco is among hundreds of so-called sanctuary cities that do not cooperate fully with federal immigration officials 

The White House, though, claimed in a written statement that the bill "fails to offer comprehensive reforms needed to fix the Nation's broken immigration laws and undermines current Administration efforts to remove the most dangerous convicted criminals and to work collaboratively with State and local law enforcement agencies." 

According to the White House, it would "essentially turn State and local law enforcement into Federal immigration law enforcement officials, in certain circumstances." 

Only two Democrats voted Tuesday to advance the bill, Sens. Joe Donnelly of Indiana and Joe Manchin of West Virginia. Illinois Sen. Mark Kirk was the only Republican to vote "no." 

The legislation would have made it illegal for local governments to ignore immigration-related detainers -- federal requests to notify them before releasing an illegal immigrant so they can take custody -- and to bar local officials from sharing immigration information with federal agents. 

The bill called for withholding certain federal funding to any local governments that flout the policy. 

The issue, though, became a political football not only on the presidential campaign trail but on Capitol Hill. 

In advance of the vote, Senate Democratic Leader Harry Reid said on the floor: 

"This vile legislation might as well be called 'The Donald Trump Act.' Like the disgusting and outrageous language championed by Donald Trump, this legislation paints all immigrants as 'criminals and rapists.'" 

As Congress stalled on the sanctuary city matter, some state governments already are taking action. North Carolina lawmakers recently voted to make their state the first prohibiting such policies at the local government level. 

Fox News' Kara Rowland contributed to this report.