By Joe Wallace and Michael Wursthorn

U.S. stocks surged Wednesday toward their biggest-ever postelection gain, led by a rally in technology shares, as investors appeared to coalesce around the idea of a divided U.S. government.

Although the outcome of the presidential election remained uncertain as crucial battleground states like Georgia, Michigan and Pennsylvania continued to tally votes, neither Republicans or Democrats received a clear mandate from voters that would preface broad policy changes, analysts and traders said.

The broad S&P 500 index gained 2.4% in recent trading, on course for its best performance on the day after a presidential election on record. The Dow Jones Industrial Averaged added more than 400 points, or 1.7%. The tech-heavy Nasdaq Composite jumped even higher, gaining 3.7%.

So far, Republicans appeared poised to remain in control of the Senate, while the odds of former Vice President Joe Biden topping President Trump in the electoral count brightened. Democrats, meanwhile, will likely keep control of the House, but with a slimmer margin. Those outcomes are sure to hamper any ability by Democrats to push a progressive agenda, including changes to taxes, health care and how tech companies are regulated.

"Now, it looks like there's going to be more political gridlock," said RJ Grant, a director of equity trading at KBW Inc.

But those developments also throw a wrench into an easy pathway for additional fiscal stimulus that some analysts say is needed to help the economy recover from the damage wrought by the coronavirus pandemic.

With little else certain, investors appeared to back off from buying shares of economically sensitive companies, the "blue-wave trade" that had been gaining traction ahead of the election on the expectation of another round of economic aid. Instead, investors reverted back to snapping up the stock market's most enduring winners, shares of technology companies.

Rob Manning, senior managing director and head of trading at Evercore ISI, said many of the firm's hedge-fund clients were buyers of shares of technology, communication services and even health-care companies on Wednesday. That was a reversal from last week, when hedge funds were net sellers of technology stocks and net buyers of value-oriented companies, including in the industrial, financial and real-estate sectors.

He added the firm's derivatives traders saw many investors unwind the hedges they had placed on tech stocks to protect against any election uncertainty, as well as a Democratic sweep.

"We're seeing a move back into what has worked in the market this year," Mr. Manning said.

At the same time, investors scooped up government bonds, putting U.S. Treasury yields on pace for their biggest one-day drop in months, further suggesting investors' stimulus expectations have fallen. A measure of volatility, the Cboe Volatility Index, or VIX, receded, falling 16%.

The stock market's solid gains followed a wild night of off-hours trading. S&P 500 futures had briefly turned red after President Trump accused Democrats of trying to disenfranchise his voters and promised to petition the Supreme Court, though he didn't elaborate.

They turned positive again after counts in Wisconsin and Michigan pointed toward possible wins for Mr. Biden, though a substantial number of ballots remain uncounted.

"The market has been underpricing the chance of a close result," said Seema Shah, chief strategist at Principal Global Investors. "I'm surprised U.S. equities are doing as well as they are," Ms. Shah added, saying she expected to see more wild swings in stock prices in the near term.

Despite the volatility, traders described Wednesday's action as orderly, saying investors largely avoided making outsize bets one way or another ahead of the election, instead opting for hedges to protect portfolios. Many tried to avoid the scenario in 2016 where many investors were caught flat footed in the wake of President Trump's victory then.

Still, the lack of a decisive result will likely keep investors on edge.

Money managers had long pinpointed a drawn-out or contested result as having the potential to spark big swings in asset prices. During the 2000 election dispute, for example, the S&P 500 fell about 4% between the election date and the Supreme Court ruling in mid-December that settled the matter.

"Markets don't want to see this long protracted multiple-week scenario play out. The market won't like that at all," said Doron Barness, a senior managing director and global head of cash equities trading and distribution.

On Wednesday, big technology stocks powered markets higher. Apple, Amazon.com and Google owner Alphabet all gained ground.

Among other movers, shares of Uber Technologies rose 13% and Lyft around 11% after California voters approved an initiative that let the ride-hailing firms count their drivers as independent contractors.

Shares of Biogen surged 40% after the U.S. Food and Drug Administration appeared to give a positive assessment of the company's experimental Alzheimer's disease drug.

Meanwhile, shares of banks and industrial stocks, which are closely tied to the outlook for the economy and tend to suffer when longer-term bond yields slide, lagged behind the gains of tech and broad index benchmarks.

Small-cap stocks, which are more exposed to economic growth and were more likely to benefit from another government spending package, broadly declined, another sign that stimulus hopes have waned. The Russell 2000 index of smaller stocks fell 0.1% in recent trading.

The slide came even after Senate Majority Leader Mitch McConnell said Wednesday that Congress should pass a new economic-relief package this year.

Without the cushion of additional stimulus, the economy will remain more exposed to the trajectory of the coronavirus, said Anna Rathbun, chief investment officer at CBIZ Investment Advisory Services.

"That's why we may see more of the same market patterns that we did maybe over the summer, maybe early fall, where we have ailing cyclicals, Treasury yields might remain depressed and small caps would in that scenario also struggle," she added.

--Mischa Frankl-Duval and Karen Langley contributed to this article.

Write to Joe Wallace at Joe.Wallace@wsj.com and Michael Wursthorn at Michael.Wursthorn@wsj.com

(END) Dow Jones Newswires

11-04-20 1559ET