Technology and health care companies led a stock market rally Wednesday, as Wall Street embraced the upside of more gridlock in Washington even as the outcome of the U.S. presidential election remained in limbo.

The S&P 500 rose 2.2% for its best day in five months. The benchmark index had been up 3.5% before the market lost some of its momentum toward the end of the day. That pullback wiped out more than 450 points from the Dow Jones Industrial Average, though the blue-chip index still closed more than 360 points higher.

The Nasdaq was the standout, notching its biggest gain in more than six months as traders doubled down on technology stocks. Health insurers were big winners, too, as prospects for an overhaul of the industry dimmed.

The fate of the U.S. presidency remains undecided as neither President Donald Trump or Democratic challenger Joe Biden had secured the 270 Electoral College votes needed to win by Wednesday afternoon. But after a tumultuous overnight session in global markets where Trump prematurely declared victory, Wall Street acted as if the occupant of the White House might be secondary.

Analysts said the gains came as markets focused on the benefits of the country’s political control remaining split between Democrats and Republicans. With Republicans edging closer to retaining control of the Senate, prospects dimmed for the tax increases and tighter regulations on businesses that investors expected if Democrats scored an electoral sweep, although a big stimulus effort for the economy that some on Wall Street say is needed now seems unlikely as well.

“The first information that people are digesting is that a split government is OK, and we can deal with this,” said Melda Mergen, deputy global head of equities at Columbia Threadneedle. “No big changes are expected anytime soon on the policy side.”

She cautioned, though, that the initial moves for the market may not last. “It’s a very quick reaction without knowing the final results,” she said. “It’s emotional rather than rational.”

The S&P 500 rose 74.42 points to 3,443.44. The Dow added 367.63 points, or 1.3%, to 27,847.66. The Nasdaq gained 430.21 points, or 3.9%, to 11,590.78.

Much of Wednesday’s strength for Wall Street was due to big gains for technology stocks. Investors have increasingly seen these stocks as some of the safer bets in the market, able to grow their profits even in a pandemic as more of daily life shifts online.

They don’t need a big stimulus effort for the economy as much as other companies, and the likelihood of Washington approving such a package dropped with the chances of a Democratic sweep. That led to the much better performance for the tech-heavy Nasdaq over other indexes. Microsoft rose 4.8%, Amazon climbed 6.3%, Facebook surged 8.3%, and Google’s parent company gained 6.1%.

Cigna, UnitedHealth Group and Anthem were among the biggest gainers in the S&P 500, as investors bid up health care stocks.

Other areas of the stock market, where profits are more dependent on the strength of the economy, lagged behind. Financial stocks in the S&P 500 dropped 1.3%. Companies that make construction materials and could have benefited from a big infrastructure plan under a Democratic sweep also fell.

Some of the market’s sharpest moves overnight were in yields for U.S. government bonds, which had earlier risen on growing expectations for big economic stimulus.

The 10-year Treasury yield swung from 0.88% late Tuesday up to 0.94% as polls were closing. It then sank as low as 0.75% after Trump made premature claims of victories in several key states, Republicans held onto Senate seats and a couple economic reports came in weaker than expected. It slipped to 0.76% in late-afternoon trading.

All the swings are a bit reminiscent of four years earlier, when Trump surprised the market by winning the White House. Markets initially tumbled after polls and the market’s expectations proved to be so wrong in 2016, but they quickly turned around on expectations that Trump’s pro-business stance would be good for corporate profits.

The difference this time is that the uncertainty seems set to linger. It may take days for a winner of the White House to emerge, and professional investors say they’re bracing for sharp market swings in the meantime. The Trump campaign on Wednesday filed lawsuits over the voting in Michigan and Pennsylvania, and earlier the president said he’d take the election to the Supreme Court, though it’s unclear exactly what he means by that.

A drawn-out court battle “just adds more and more uncertainty, and the last thing the market needs is that,” said Quincy Krosby, chief market strategist at Prudential Financial.

Many fund managers suggest investors hold steady through the tumult in large part because one person can’t singlehandedly move the economy and stocks tend to rise regardless of which party controls the White House. What happens with the coronavirus pandemic is likely to have a much greater effect on markets than this election’s results, they say.

“It’s really about the solution to the health crisis and how do we bridge between now and that eventual period of time,” said Bill Northey, senior investment director at U.S. Bank Wealth Management.

Uber soared 14.6% and Lyft jumped 11.3% after the ride-hailing companies won a vote in California allowing them to continue classifying their drivers as contractors instead of employees and preserve their business models.

European markets also closed broadly higher. Besides the election’s impact on Trump’s enthusiasm for tariffs, European investors are also watching what it will do to the U.S. dollar’s value. By making additional stimulus less likely, a divided U.S. government could force the Federal Reserve to do even more on its own to support the economy, which could send the dollar lower against the euro and other currencies.

The Fed will announce its latest decision on interest-rate policy on Thursday. Its moves earlier this year to slash interest rates to record lows and prop up bond markets have helped Wall Street soar since March.