WASHINGTON — The Senate on Thursday easily voted to overturn President Trump’s declaration of a national emergency at the southwestern border, delivering a bipartisan rebuke to what lawmakers in both parties deemed executive overreach by a president determined to build his border wall over Congress’s objections.

The 59-41 vote on the House-passed measure sets up the first veto of Mr. Trump’s presidency. It was not overwhelming enough to override Mr. Trump’s promised veto, but Congress has now voted to block a presidential emergency declaration for the first time — and on one of the core promises that animated Mr. Trump’s political rise, the vow to build a wall between the United States and Mexico.

“Never before has a president asked for funding, Congress has not provided it, and the president then has used the National Emergencies Act of 1976 to spend the money anyway,” Senator Lamar Alexander, Republican of Tennessee, said. “The problem with this is that after a Revolutionary War against a king, our nation’s founders gave to Congress the power to approve all spending so that the president would not have too much power. This check on the executive is a crucial source of our freedom.”

In an attempt to limit defections ahead of the vote, Mr. Trump had sought to frame the vote publicly as not only a declaration of support for his border security policies but a sign of personal loyalty.

[Sign up for Crossing the Border, a limited-run newsletter about life where the United States and Mexico meet.]

“It’s pure and simple: it’s a vote for border security, it’s a vote for no crime,” Mr. Trump told reporters ahead of the vote, which he declared on Twitter to be “a vote for Nancy Pelosi, Crime and the Open Border Democrats!”

But he could not overcome concerns among Republican senators about the legality of redirecting $3.6 billion from military construction projects toward the border wall even after Congress explicitly rejected the funding request.

“I believe the use of emergency powers in this circumstance violates the Constitution,” said Senator Jerry Moran, Republican of Kansas, in a statement written on lined paper. “This continues our country down the path of all powerful executive — something those who wrote the Constitution were fearful of.”

The vote marks an explicit rebuke of Mr. Trump’s effort to sidestep the constitutional power of the purse given to Congress, and although supporters will not be able to overcome a veto, the action could bolster a number of lawsuits contesting the emergency declaration as a flagrant violation of the Constitution’s separation of powers.

The number of Republican defections underscores the turmoil within the Republican Conference, where senators were torn between supporting the president’s vision for border security and asserting Congress’s constitutional prerogative to dictate federal spending.

Senator Thom Tillis, Republican of North Carolina and one of the first to publicly say he would support the resolution, announced he had changed his mind just minutes before the vote. Facing a tough re-election campaign in 2020, he said that conversations with the White House and his colleagues contributed to his changed vote. He had also been warned in recent days by North Carolina conservatives that he could face a primary challenger for his stand.

Three Republican senators — Lindsey Graham of South Carolina, Ben Sasse of Nebraska and Ted Cruz of Texas — interrupted Mr. Trump’s dinner with his wife, Melania, at the White House Wednesday night to share their concerns about the constitutional precedent that Mr. Trump had established. Mr. Graham said he asked for the meeting because he considered Mr. Sasse and Mr. Cruz “good guys” and hoped to limit the number of defections.

Mr. Cruz initiated the meeting, in hopes of selling Mr. Trump on his own rewrite of the emergency declaration law that would restrict funding from military sources, according to a senior Republican aide with direct knowledge of the proposal. Mr. Trump summoned a lawyer from the White House Counsel’s Office, who said the plan would strip the president of powers he currently possesses. “No way,” an annoyed Mr. Trump told the trio, according to a person with knowledge of the exchange.

“I said there’s some people want to talk to you, they have some concerns about the emergency declaration,” Mr. Graham said. “Hell, if I was him, I would have told us to go to hell.”

All three men sided with Mr. Trump and voted against the resolution.

Mr. Graham, along with other lawmakers supportive of the declaration, argued that the president’s declaration was within the jurisdiction of the National Emergencies Act, and was needed to address what the president and his supporters deem to be a crisis at the southwestern border.

“I take Congress’s prerogative over appropriations extremely seriously,” said Senator Mitch McConnell of Kentucky, the majority leader. “But,” he added, “the Senate should not be in the business of misusing specific resolutions to express opinions on more general matters.” Mr. Trump, at Mar-a-Lago, told an associate that he felt let down by lackluster support for him among Republican leadership.

Mr. McConnell, who strongly advised Mr. Trump against declaring the emergency declaration, made a point of not pressuring senators to support Mr. Trump, urging them to vote according to their consciences and political interests, according to seven Republican aides and lawmakers.

At a party lunch in early March, the leader canvassed his conference and found virtually no support for the president’s position — then he informed senators running for re-election that they were free to vote “the politics” if they chose, according to a person in attendance.

He also repeatedly told senators that he had warned against Mr. Trump against enacting the emergency declaration in the first place.

In a volley of phone calls with Senate Republicans over the last few weeks, the president warned of the electoral consequences of defying his will and dismissed concerns about the constitutional precedent of his order.

Image

Ultimately, a dozen Republicans joined Senate Democrats in supporting the House-passed resolution of disapproval, including Senator Mitt Romney, Republican of Utah.CreditSarah Silbiger/The New York Times

The president attempted to cajole a handful of members to vote his way during a meeting on trade at the White House on Wednesday afternoon, emphasizing that a vote “against border security,” would be noticed by the party’s base, according to two people who attended.

But Mr. Trump also personally sunk attempts by Republican senators this week to limit the number of defections to a handful, an endeavor that would have saved the president a second embarrassing loss in a week that also featured a bipartisan rebuke of his dogged support for Saudi Arabia’s war in Yemen, even after the killing of the dissident journalist Jamal Khashoggi.

When Mr. Paul, a libertarian who frequently bucks his party, announced his support for the resolution, the president flew into a rage, according to two people with knowledge of the situation — and called Mr. Paul to demand that he reverse himself. The senator refused, although the two have since reconciled.

And when Mr. Lee proposed an alternative measure — a bill that would restrict future uses of emergency declarations, but leave Mr. Trump’s order in place — and discussed it in a meeting with other undecided senators and Vice President Mike Pence, Mr. Pence expressed support, according to multiple people briefed on the meeting.

The next day, Mr. Trump called the Utah Republican in the middle of a Republican policy lunch to inform him that he did not, in fact, support the measure. Mr. Lee, who announced the president’s verdict to gasps from his colleagues, later declared his support for the resolution.

On Thursday, before the vote, Mr. Trump said that he would support efforts to update the 1976 law “at a later date.”

It also remains unclear what military construction projects will be affected by the president’s national emergency declaration. Multiple Republican senators, including Mr. Portman and Mr. Alexander, had urged the president to leave the construction funds alone and instead use more typical presidential authority to pull from other programs.

At a Senate Armed Services hearing on Thursday morning, acting Defense Secretary Patrick M. Shanahan said that up to 40 percent of the American troops currently on the southwest border with Mexico would be pulled back over the next month.

He said that would reduce the number of troops to no more than 4,000; there are currently around 6,000 — 2,000 National Guard and the rest active duty.

Pressed by Senator Mazie Hirono, Democrat of Hawaii, on whether he considered the border mission as protecting from a military threat, Mr. Shanahan said he did not.