Donald Trump has threatened to use his presidential veto after the US Senate delivered a sharp rebuke to the president on Thursday, voting to overturn his declaration last month of a national emergency in order to divert taxpayer funds to the US-Mexico border.

In a 59-41 vote, 12 Republicans joined every Senate Democrat in a rare move to block the president’s effort to divert billions in funding to build his long-promised border wall without congressional approval.

The Democratic-controlled House passed the measure last month, and its approval in the Senate will probably force Trump to use the first veto of his presidency. The defections on Thursday fell far short of the 67 votes needed to override the veto, however.

Moments after the vote, Trump tweeted simply: “VETO!” He later added praise for “all of the Strong Republicans who voted to support Border Security and our desperately needed WALL!”

Earlier on Thursday, Trump had attempted to constrain the defections by warning Republicans that a “vote for today’s resolution by Republican Senators is a vote for Nancy Pelosi, Crime, and the Open Border Democrats!”

But Trump ultimately failed to allay the concerns within his party that the action violated the constitution’s separation of powers, which confers the power of the purse to Congress.

“I believe the use of emergency powers in this circumstance violates the constitution,” said the Kansas senator Jerry Moran, a Republican. “This continues our country down the path of all-powerful executive – something those who wrote the constitution were fearful of.”

Congressman Joaquín Castro, a Texas Democrat who authored the resolution and watched the vote from the Senate floor, called the bipartisan tally a “strong condemnation” of the president’s emergency declaration that may help bolster legal challenges to the order.

The Republican senators who stood by Trump insisted that there was an immigration crisis at the southern border and that the order was well within the jurisdiction of the National Emergencies Act, which gives presidents wide-ranging latitude to declare a national emergency.

“There is an emergency at our southern border,” said Senator Lindsey Graham of South Carolina, who has become a close ally of the president and is part of a cohort of Republicans who interrupted Trump’s dinner on Wednesday night to relay their “concerns” about the emergency declaration.

Nevertheless, Graham voted against the resolution to block Trump, declaring: “I believe the president is on sound legal ground. While I respect those who disagree, it is time to build the wall.”

The vote marks the second time in as many days that Senate Republicans have defied the president. On Wednesday, Republicans joined Democrats to pass a resolution to end US support for the Saudi-led coalition in Yemen’s brutal civil war despite the Trump administration’s embrace of the nation’s monarchy.

Meanwhile in the House, Republicans joined Democrats on Thursday in an overwhelming show of support for a non-binding resolution demanding that the Department of Justice make public the findings of the special counsel Robert Mueller and the investigation he has been leading for almost two years into allegations of Russian interference in the 2016 presidential election.

The Senate minority leader, Chuck Schumer, said he hoped the back-to-back rebukes of the president’s actions were “not an aberration but a turning point”.

“Republicans – out of courage, out of principle and maybe out of exasperation – are beginning to constrain the president when he goes too far,” Schumer said. “The United States of America has no king and we never will.”

Trump declared a national emergency last month after signing a funding agreement that did not include the money he requested to build a wall. His signature ended a 35-day partial shutdown of the federal government, which was triggered by a showdown after Congress refused to appropriate the $5.7 bn he requested to start construction at the border.

In his annual budget proposal, which Trump sent to Congress this week, the president asked for $8.6bn in funding for his wall, far more than he had previously requested.

Among the Republican senators who supported the resolution of disapproval was Mike Lee of Utah, who had proposed an alternative measure to avoid the confrontation, and Susan Collins of Maine, who faces a difficult re-election in 2020. The others included Senators Lisa Murkowski of Alaska, Mitt Romney of Utah, Marco Rubio of Florida, Patrick Toomey of Pennsylvania and Rand Paul of Kentucky.

Senator Thom Tillis, a North Carolina Republican facing a tough re-election in 2020, was among the first in the party to publicly support the resolution with an op-ed in the Washington Post but announced right before the meeting that he had changed his mind.

Trump’s emergency declaration posed a conundrum for Republicans, who spent eight years railing against what they viewed as presidential overreach by Barack Obama but who are largely in lockstep with the president on immigration.

Many Republicans are wary of defying the president and his passionate base of conservative voters who are eager to see the president fulfill his campaign promise. But they are equally alarmed by his use of the four-decade-old law to circumvent congressional authority – a move that could set a precedent for future Democratic presidents.

Trump is anticipated to use the veto, meaning the best chance of blocking his emergency declaration may come through the courts, where the action faces several legal challenges from Democratic state attorneys general, borderland residents and environmental groups.