WASHINGTON — With the federal government on the brink of a default, a House Republican effort to end the shutdown and extend the Treasury’s borrowing authority collapsed Tuesday night as a major credit agency warned that the United States was on the verge of a costly ratings downgrade.

After the failure of the House Republican leadership to find enough support for its latest proposal to end the fiscal crisis, the Senate’s Democratic and Republican leaders immediately restarted negotiations to find a bipartisan path forward, and one aide described an agreement as imminent.

A spokesman for Sen. Harry Reid of Nevada, the majority leader, said Reid was “optimistic that an agreement is within reach” with Sen. Mitch McConnell of Kentucky, the Republican leader.

With so little time left, chances rose that a resolution would not be approved by Congress and sent to President Barack Obama before Thursday, when the government is left with only its cash on hand to pay the nation’s bills.

“It’s very, very serious,” warned Sen. John McCain, R-Ariz. “Republicans have to understand we have lost this battle, as I predicted weeks ago, that we would not be able to win because we were demanding something that was not achievable.”

A day that was supposed to bring Washington to the edge of resolving the fiscal showdown instead seemed to bring chaos and retrenching. And a bitter fight that had begun over stripping money from the president’s signature health care law had essentially descended in the House into one over whether lawmakers and their staff members would pay the full cost of their health insurance premiums, unlike most workers at U.S. companies, and how to restrict the administration from using flexibility to extend the debt limit beyond a fixed deadline.

Even so, the House speaker, John Boehner, R-Ohio, and his leadership team failed in repeated, daylong attempts to bring their troops behind any bill that would reopen the government and extend the Treasury’s debt limit on terms significantly reduced from their original push against funding for the health care law. The House’s hard-core conservatives and some more pragmatic Republicans were nearing open revolt, and the leadership was forced twice to back away from proposals it had floated, the second time sending lawmakers home for the night to await a decision on how to proceed Wednesday.

The House setback returned the focus to the Senate.

Under the emerging Senate deal, the government would be funded through Jan. 15 and the debt limit extended until Feb. 7. House and Senate negotiators would be required to reach accord on a detailed tax-and-spending blueprint for the next decade by Dec. 13.

A proposal to delay the imposition of a tax on medical devices had been dropped from the deal, as had a complicated tax on self-insured unions and businesses participating in the health care exchanges.

It remained unclear whether the Senate plan could pass the House or even whether Boehner would bring it forward for a vote. The hopes for a resolution by Thursday also appeared to rest with the senators who had begun the failed movement to tie any further government funding to the gutting of the Affordable Care Act: Ted Cruz, R-Texas, and Mike Lee, R-Utah.

If Reid and McConnell reach a final accord, Senate leaders expect to use a parliamentary maneuver that will allow the majority leader to move the deal to the Senate floor quickly on Wednesday. But if Senate hard-liners object, the Senate would have to wait until Friday and then muster 60 votes to cut off debate.