WASHINGTON — A dozen Republicans joined Senate Democrats on Thursday to overturn President Trump’s declaration of a national emergency at the southwestern border, arguing that the president had exceeded his powers in trying to build a border wall over Congress’s objections.

The 59-to-41 vote on a measure already approved by the House set up the first veto of Mr. Trump’s presidency. It was not a big enough margin to override his promised veto, but Congress has now voted for the first time to block a presidential emergency declaration — and on one of the core promises that animated Mr. Trump’s political rise.

“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,” said Senator Lamar Alexander, Republican of Tennessee. “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.”

It was the latest sign that the cautious Republican majority in the Senate, spurred on by a far bolder Democrat-controlled House, was beginning to reassert its authority with a president who had gone virtually unchecked during his first two years in office.