NEW YORK — Stocks scored their first back-to-back gains Wednesday since a brutal sell-off began five weeks ago, but much of an early rally faded late in the day as a last-minute dispute threatened to hold up a $2 trillion economic rescue package in Congress.

The S&P 500 rose 1.2%, bringing its two-day gain to 10.6%. It had been up 5.1% earlier in the day as Congress moved closer to approving the plan to provide badly needed aid to an economy that has been ravaged by the coronavirus. The market is now down nearly 27% since setting a record high a month ago.

Many on Wall Street say they don’t think stocks have hit bottom yet, but optimism rose after the White House and Senate leaders announced an agreement on the aid bill early Wednesday. A vote had been expected in the Senate by the end of the day, but then some lawmakers balked at the proposed bill.

GOP Senators Tim Scott, Ben Sasse and Lindsey Graham demanded changes, saying the legislation as written “incentivizes layoffs” and should be altered to ensure employees don’t earn more money if they’re laid off than if they’re working. Complicating the standoff, Sen. Bernie Sanders, of Vermont, said he would block the bill unless the conservatives dropped their objections.

Investors were anxiously waiting for the aid in the rescue package, which lawmakers hope will help blunt the blow to the economy as businesses shut down to slow the spread of the coronavirus.

“They’re hitting on all the right elements of what the U.S. economy needs during the shutdown to bridge itself to the other side to open up economic activity,” said Darrell Cronk, chief investment officer of Wells Fargo Wealth and Investment Management.

But even optimists say the package provides just the second leg of three that markets need to regain lasting confidence. The Federal Reserve and other central banks are also offering tremendous aid by cutting interest rates and supporting lending markets, but investors say they need to see the number of new infections peak before they can feel comfortable knowing how deep the looming economic downturn will be.

“There’s a lot of bad news, there’s very little tangible good news and there’s a lot of uncertainty in between,” said Jack Ablin, chief investment officer at Cresset.

Investors are also still waiting to see the details of Washington’s plan, which will include direct payments to most Americans and aid for hard-hit industries. It’s unclear when the House would vote on the plan.

Copyright 2020 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed without permission.