WASHINGTON — The Senate on Thursday failed to overturn President Trump’s veto of a resolution that would have terminated the national emergency he declared at the southwestern border. The defeat allows Mr. Trump to continue to defy Congress and divert federal funds to the construction of a border wall, his signature campaign promise.

The override attempt, the second such effort this year, failed when it fell short of the two-thirds majority needed to nullify a veto. But the 53-to-36 vote reflected concern among lawmakers in both parties about protecting Congress’s power to allocate federal funds and opposition to Mr. Trump’s plans to transfer billions of dollars in military construction money to build the border barrier.

Ten Republicans joined Democrats in supporting the measure.

Mr. Trump issued the veto Tuesday night, exactly seven months after using his first presidential veto to turn back a nearly identical resolution. Under the law, Congress can vote on such legislation every six months, and Democrats have used every opportunity to force Republicans to go on the record and choose whether to break with Mr. Trump, defending their prerogatives as legislators, or side with him.

The president declared the national emergency in February, after Democrats and Republicans in Congress rejected his efforts to secure $5 billion for the border wall, including during a 35-day government shutdown in which he repeatedly refused to accept any funding measure that failed to fund the edifice. The declaration, which Democrats have challenged in court, was Mr. Trump’s attempt to unilaterally seize money to pay for it anyway.