After weeks of political impasse, tense negotiations and mounting economic anxiety, the Senate gave final approval on Thursday night to bipartisan legislation suspending the debt limit and imposing new spending caps, sending it to President Biden and ending the possibility of a calamitous government default.

The approval by the Senate on a 63-to-36 vote brought to a close a political showdown that began brewing as soon as Republicans narrowly won the House in November, promising to use their new majority and the threat of a default to try to extract spending and policy concessions from Mr. Biden.

The president refused for months to engage with Speaker Kevin McCarthy but finally did so after the California Republican managed in April to pass a G.O.P. fiscal plan, spurring negotiations with the White House that produced the compromise last weekend.

On Thursday night, Mr. Biden cheered its passage, promising to sign it as soon as possible and address the nation from the Oval Office on Friday evening.

“Tonight, senators from both parties voted to protect the hard-earned economic progress we have made and prevent a first-ever default by the United States,” he said. “No one gets everything they want in a negotiation, but make no mistake: This bipartisan agreement is a big win for our economy and the American people.”

The agreement suspends the $31.4 trillion debt limit until January 2025, allowing the government to borrow unlimited sums to pay its debts and ensuring that another fight will not occur before the next presidential election. It sets new spending levels that will be tested as Congress begins to write its annual spending bills. Other policy changes on energy project permitting and work requirements on social benefits were also included.

“We saved the country from the scourge of default,” Senator Chuck Schumer, Democrat of New York and the majority leader, exulted after the bill cleared Congress.

The Senate vote came after an afternoon of closed-door talks to resolve a last-minute flare-up over Pentagon funding, ignited by Republicans who said the debt-limit package severely underfunded the military. Senate leaders resolved the dispute with a formal statement that the debt-limit deal “does nothing to limit the Senate’s ability to appropriate emergency supplemental funds to ensure our military capabilities.”

The statement came after a day of uncertainty as a handful of Republican defense hawks complained that the deal — negotiated without input from the Senate — would under-fund the military, and they demanded a commitment that their concerns would be addressed before it could be passed.

By evening, Senate officials and Senator Lindsey Graham, the South Carolina Republican who had been a chief critic of the Pentagon spending levels, said the pledge from the leadership was sufficient to reassure him and other critics sufficiently to back the bill, clearing the way for final votes.

“It does not fix this bill totally, but it is a march in the right direction,” Mr. Graham said.

Democrats contended that the entire debt-limit episode should have never occurred and that Mr. McCarthy should not be rewarded for using the nation’s economy as a hostage to win spending cuts. But they said the prospect of a default needed to be avoided at all costs.

“Defaulting on our national debt is unacceptable, unthinkable,” said Senator Richard J. Durbin of Illinois, the No. 2 Democrat, who accused Mr. McCarthy of a “careless and reckless” act. “We cannot let it occur.”

As in the House, Democrats carried the measure to passage in the Senate, with 44 of them and two independents joining 17 Republicans in support; 31 Republicans, four Democrats and one independent voted no.

The debt-limit agreement, which was approved overwhelmingly by the House on Wednesday night, increases Pentagon spending to $886 billion for next year, a 3 percent rise. But Republican backers of higher spending for the military noted that that would not keep pace with inflation, and argued that the package fell far short of what was needed.

“To my House colleagues, I can’t believe you did this,” Mr. Graham said earlier in the day, accusing the architects of the measure of undercutting the military at a time of rising threats from Russia and China. “This budget is a win for China.”

Mr. Graham and others insisted, at minimum, on a commitment that Congress would later act on an additional funding bill to beef up the spending, although this would in effect reduce the savings Republicans had hoped to achieve through their debt limit deal.

“We know that this budget is not adequate to the global threats that we face,” said Senator Susan Collins of Maine, the senior Republican on the full Appropriations Committee. “An emergency supplemental must be coming our way.”

The opposition erupted almost immediately after Mr. Schumer opened the Senate on Thursday morning by warning that the chamber needed to move quickly and make no changes to the agreement to clear it for Mr. Biden’s signature by Monday. He admonished lawmakers not to engage in brinkmanship before the so-called X-date of June 5, when Treasury Secretary Janet L. Yellen said the government would default without action by Congress.

“Time is a luxury the Senate does not have if we want to prevent default,” Mr. Schumer said. “June 5 is less than four days away. At this point, any needless delay or any last-minute holdups would be an unnecessary and even dangerous risk.”

Even as the deal migrated across the Capitol, the effects of the debt limit continued to pinch. The Treasury Department announced on Thursday that it would delay auctions of three-month and six-month “bills” — short-term debt that the government no longer has room to take on until the borrowing cap is suspended.

As part of the deal to move forward with final votes on the bill, multiple senators secured votes on proposed changes. Mr. Schumer was determined to defeat all of them, as any alteration would force the measure back to the House, where no action would be likely to occur before the default deadline.

“Any change to this bill that forces us to send it back to the House would be entirely unacceptable,” he said. “It would almost guarantee default.”

After driving much of the legislative agenda the previous two years, the Senate left negotiating on the debt limit to Mr. Biden and Mr. McCarthy, whose demand for spending cuts and other policy changes brought the country to the brink of default. Nearly all Republican senators signed a letter backing Mr. McCarthy in the effort. As a result, senators had little influence over the negotiations and were forced to approve legislation they did not help shape. It was leaving some frustrated.

Senator John Cornyn, Republican of Texas, praised Mr. McCarthy’s efforts but said senators had no obligation to simply rubber stamp the deal and deserved opportunities to change it.

“We weren’t a party to the agreement,” he said. “Why should we be bound by the strict terms of that agreement? The Senate has not had a say in the process so far.”

But Senator Mitch McConnell of Kentucky, the minority leader, urged his fellow Republicans to back the plan.

“Last night, an overwhelming majority of our House colleagues voted to pass the agreement Speaker McCarthy reached with President Biden,” he said. “In doing so, they took an urgent and important step in the right direction for the health of our economy and the future of our country.”

Catie Edmondson, Jim Tankersley and Joe Rennison contributed reporting.