(Reuters) - A dramatic session on Wall Street ended with stocks slightly lower on Friday as they pared losses in late-afternoon trading after Republicans pulled their bill to overhaul the U.S. healthcare system.

The benchmark S&P 500 shot up briefly into positive territory before falling back into the red as Republicans pulled the legislation due to a shortage of votes just before the markets closed, leaving investors to assess how the healthcare bill’s failure would affect President Donald Trump’s broader economic agenda.

Investors had worried earlier this week that the failure of the bill, which would have dismantled the law known as Obamacare, would prove an ominous sign for Trump’s ability to push through his economic agenda, including tax reform.

But some analysts and investors have seen a failure of the bill as a catalyst to bring forward action on tax reform in particular.

“Now that they’ve taken the healthcare issue off the table, I think the market is more optimistic that they can do other things that are more doable that are not so complicated, such as regulatory reform and lowering taxes,” said Margaret Patel, senior portfolio manager at Wells Fargo Asset Management in Boston.

The Dow Jones Industrial Average .DJI fell 59.86 points, or 0.29 percent, to end at 20,596.72, the S&P 500 .SPX lost 1.98 points, or 0.08 percent, to 2,343.98 and the Nasdaq Composite .IXIC added 11.05 points, or 0.19 percent, to 5,828.74.

The back-and-forth over the bill this week has led to some of the most volatile trading Wall Street has seen since Trump’s election in November. For the week, the S&P 500 fell 1.4 percent, its worst weekly decline of the year.

“This is now an indication that the president’s agenda is probably going to be more ambitious than Congress can manage,” said Peter Kenny, senior market strategist at Global Markets Advisory Group, in New York. “It is probably going to mean that equity markets are going to have to factor in a degree of dysfunction that investors were hoping they wouldn’t have to.”

The S&P 500 has climbed 9.6 percent since Trump’s election, notching a series of record highs along the way. But the rally has stalled recently, and Tuesday’s 1.2 percent drop set off concerns about the beginning of a larger fall.

“The economy and earnings were doing better since before the election,” said Paul Zemsky, chief investment officer for multi-asset strategies and solutions at Voya Investment Management in New York. “If people want to drop the S&P by 300 points because this doesn’t pass, I and others will be down there to buy it.”

Shares of hospital operators finished sharply higher, with Tenet Healthcare THC.N up 7.4 percent. The potential dismantling of Obamacare has pressured hospital stocks over concerns the benefits the companies gained from coverage expansion would diminish.

In corporate news, Micron Technology MU.O jumped 7.4 percent after the chipmaker's revenue and profit forecasts beat expectations. The stock was the biggest percentage gainer on the S&P and helped lift the Nasdaq.

GameStop GME.N tumbled 13.6 percent after the company's profit projection fell below estimates.

Advancing issues outnumbered declining ones on the NYSE by a 1.07-to-1 ratio; on Nasdaq, a 1.30-to-1 ratio favored advancers.

The S&P 500 posted 19 new 52-week highs and three new lows; the Nasdaq Composite recorded 58 new highs and 40 new lows.

About 6.2 billion shares changed hands in U.S. exchanges, below the 7.1 billion daily average over the last 20 sessions.