The US Senate has approved a fiscal deal between the White House and congressional Republicans, ending a weeks-long political stand-off over the debt ceiling that risked triggering an unprecedented default in the world’s largest economy.

Lawmakers in the upper chamber passed the bill with overwhelming bipartisan support on Thursday evening, with 63 senators backing the legislation and 36 opposed. The House of Representatives had given its green light to the deal on Wednesday night.

The bill now heads to President Joe Biden for his signature, just four days before the US Treasury projected it would run out of cash to pay all its bills. Such a scenario would have dealt a traumatic hit to the global economy and financial markets and represented a huge self-inflicted wound for Washington.

“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,” Biden said after the vote. “Together, they demonstrated once more that America is a nation that pays its bills and meets its obligations — and always will be.”

The agreement raises the US borrowing limit until 2025 and sets caps on government spending for the next two years, putting more restrictions on US fiscal policy until at least after the next presidential election.

“It is so good for this country that both parties have come together at last to avoid default,” Chuck Schumer, the Democratic Senate majority leader, said in a statement to the chamber before voting began. “America can breathe a sigh of relief.”

The Senate vote capped weeks of drama in Washington, including tense talks between Biden aides and negotiators for Republican House Speaker Kevin McCarthy. The two sides reached an agreement on Saturday.

Biden and congressional leaders then embarked on a push to convince rank-and-file members to vote quickly and approve the deal despite a highly polarised political climate.

The debt ceiling stand-off will prove less painful for investors than a similar showdown in 2011 between former president Barack Obama and John Boehner, then the Republican Speaker of the House. That brush with default resulted in a downgrade of the US’s triple A credit rating by Standard and Poor’s and a sharp sell-off in equities.

There was still palpable relief in corporate America at the resolution of the debt ceiling row. “The president and Congress averted an economic catastrophe while also laying the groundwork for more responsible fiscal policy moving forward,” said Suzanne Clark, chief executive of the US Chamber of Commerce.

The White House and members of Biden’s Democratic party have explored other options to avoid future debt ceiling battles, including a legal justification for not respecting the borrowing limit by invoking the 14th amendment of the Constitution.

The amendment states that the “validity” of the US public debt “shall not be questioned”, raising the possibility that the debt limit itself is unconstitutional.

While Biden and McCarthy had reached a bipartisan agreement to end the impasse, they faced a backlash from members of their respective parties. In the House, some far-right conservatives had even suggested trying to oust McCarthy from the speakership

In the Senate, most Republicans opposed the agreement.

“This is a missed opportunity to get government growth under control and put our nation on a sustainable fiscal path,” said John Barrasso, the Republican senator from Wyoming, after the vote. “Much more needs to be done if we’re serious about tackling the debt and beating back inflation.”

Janet Yellen, the US treasury secretary, insisted there was no good alternative. “This legislation protects the full faith and credit of the United States and preserves our financial leadership, which is critical to our economic growth and stability”, she said.