WASHINGTON, June 1 (Reuters) - The U.S. Senate on Thursday passed bipartisan legislation backed by President Joe Biden that lifts the government's $31.4 trillion debt ceiling, averting what would have been a first-ever default.

The Senate voted 63-36 to approve the bill that was passed on Wednesday by the House of Representatives, as lawmakers raced against the clock following months of partisan bickering between Democrats and Republicans.

The Treasury Department had warned it would be unable to pay all its bills on June 5 if Congress failed to act by then.

"We are avoiding default tonight," Senate Majority Leader Chuck Schumer said on Thursday as he steered the legislation through his 100-member chamber.

Biden praised Congress' timely action. "This bipartisan agreement is a big win for our economy and the American people," the Democratic president said in a statement, adding that he will sign it into law as soon as possible. He said he would make an additional statement on Friday.

Before the final vote, senators tore through nearly a dozen amendments - rejecting all of them during a late-night session in anticipation of Monday's deadline.

With this legislation, the statutory limit on federal borrowing will be suspended until Jan. 1, 2025. Unlike most other developed countries, the United States limits the amount of debt the government can borrow, regardless of any spending allocated by the legislature.

Schumer and his Republican counterpart Minority Leader Mitch McConnell delivered on their promise to do all they could to speed along the bill negotiated by Biden and Republican House Speaker Kevin McCarthy.

"America can breathe a sigh of relief," Schumer said in remarks to the Senate.