The latest attempt at immigration reform, including protections to prevent “Dreamers” from being deported, collapsed in the Senate Thursday as a bipartisan bill seen as having the best chance at passage failed to get enough support to advance.

President Trump had threatened to veto the bill — which shielded the young immigrants in exchange for $25 billion in border security — because it did not include the curbs on legal immigration he sought.

The breakdown in the Senate likely leaves the fate of Dreamers in the hands of federal courts. Two federal judges have temporarily blocked Trump from ending the Obama-era Deferred Action for Childhood Arrivals on March 5. But Trump administration attorneys are seeking relief from the Supreme Court, which could announce as soon as Friday whether it will decide the matter.

It marked the first veto threat of Trump’s presidency, a bold move against an effort that had been painstakingly crafted by a group of 16 senators — Republicans, Democrats and one independent — working for weeks behind closed doors to reach a consensus.

Trump said in a tweet shortly before the vote that passage would be a “total catastrophe,” in part because it did not include limits the White House wants on family visas and the diversity lottery.

The Senate voted 54-45 to advance the measure from Sen. Mike Rounds (R-S.D.) and Sen. Angus King (I-Maine). But it failed to reach the 60 votes needed to break a GOP-led filibuster.

Three Democrats voted against, including Sen. Kamala Harris of California and the two senators from New Mexico, Sen. Tom Udall and Sen. Martin Heinrich, mainly out of a concern that the border security provisions went too far. Eight Republicans – those who were part of the bipartisan accord – voted in favor.

The White House and Republican leaders put their muscle behind a rival measure from Sen. Charles E. Grassley (R-Iowa), the chairman of the Judiciary Committee, that would protect the Dreamers — immigrants brought to the U.S. illegally as children — and provide border security funds, but also severely limit legal immigration in the future.

It, too, failed to advance, showing the limits of a Republican-only strategy that fell largely along party lines. The Trump-backed measure drew less support than the bipartisan measure, failing 39-60.

Senators from the bipartisan group, disappointed that the White House and GOP leaders tipped the scales against their proposal, vowed to try again after Congress returns from a recess next week.

“Even though we don’t have a way laid out with bipartisan support yet, we’re the closest thing on the menu,” Rounds said. “The leadership’s between a rock and a hard place, too, we get that.”

A resolution, though, remains difficult, especially amid Trump’s fluctuating views on immigration and as both parties seek advantage with voters ahead of the midterm election.

Just last month, Trump told senators meeting at the White House on immigration policy that whatever bipartisan solution they could develop for young Dreamers facing deportation, he would sign into law.

But Trump’s commitment proved fleeting. Though he had originally promised to help Dreamers, he ultimately was convinced by aides and conservative lawmakers to use the sympathy for Dreamers to exact broader limitations on legal immigration.

Trump’s harsh criticism of the Rounds-King compromise marks a hardening of his immigration position.

“President Trump has shown a remarkable ability to snatch defeat from the jaws of victory,” said Senate Minority Leader Charles E. Schumer (D-N.Y.) on the Senate floor.

But the president wasn’t acting alone, as Republican leaders, who had promised a free-wheeling and open debate, threw their support behind the White House’s preference, making sure the bipartisan effort was hobbled before the final vote.

Senate Majority Leader Mitch McConnell and his leadership team appeared confident they could blame Democrats, after Schumer led his party into a three-day government shutdown to force the immigration votes, for failing to embrace the White House effort.

“The president’s provided a chance for these young people,” said Sen. John Cornyn (R-Texas). “It’s not Republicans’ fault.”

The Department of Homeland Security also launched a scathing attack on the Rounds-King bill ahead of Thursday’s votes in a move that stunned some senators.

Sen. Lindsey Graham (R-S.C.) said the department had “lost credibility” in acting like a “political organization” instead of offering constructive input.

“It seems as if DHS is intent on acting less like a partner and more like an adversary,” Graham said in a statement.

The final votes, though, showed how far the brief, but intense, debate this week has moved senators from their staunch positions.

Democrats compromised by providing Trump $25 billion for beefed up border security, well beyond what had been imaginable at the start of the debate when just $1.8 billion in border funding was on the table.

Democrats also gave up efforts to provide legal protections for the parents of Dreamers, who in most cases violated immigration laws by bringing the children with them illegally into the country. It was a huge concession, especially as Dreamers have fought to shield their parents from deportation.

For Republicans, the willingness to reconsider DACA, an Obama-era program they railed against as illegal, is substantial. They have largely agreed that Dreamers should be allowed to remain in the United States, and be able to pursue a path to citizenship.

Both the White House proposal, and the one from the bipartisan group, would allow the immigrants, after 10 years,to apply for citizenship if they are working and otherwise law abiding.