By Anna Hirtenstein and Dawn Lim

U.S. stocks swung between small gains and losses Wednesday, a day after the S&P 500 set its first record close since February, as investors held out cautious hopes for a continued economic recovery.

The broad stock-market index was down 0.4% as of the 4 p.m. close of trading in New York, while the Dow Jones Industrial Average was off 0.3%. The technology-heavy Nasdaq Composite fell 0.6%.

The S&P 500 has surged more than 50% from its lows in March and is up more than 5% for the year. After a remarkable rally in April and May, the index has gradually crept higher in recent weeks.

"We've had the sharpest selloff in history from a record high to a bear market," said Phil Orlando, chief equity market strategist at Federated Hermes. "We followed that up with the sharpest rebound in history from a bear market to a new record high."

A string of recent economic data has pointed to signs of a rebound in the American labor market, the manufacturing sector and consumer spending. But some investors remain nervous about the sustainability of a market rebound, largely spurred by the Federal Reserve's interventions.

The Fed has taken aggressive action to prop up bond markets, pushing yields down. Low yields have driven investors to seek out riskier assets like equities.

Stocks lost some of their momentum after the Fed released minutes of a July meeting where they grappled with how to spur growth amid low rates and rising virus cases.

Fed officials said the U.S. needed greater support recovering from the coronavirus pandemic but were hazy about when they should deploy their tools. They expressed limited enthusiasm for yield curve control, a policy that typically involves targeting rates and pledging to buy longer-term bonds.

"It was a mechanism for providing stimulus that the Fed has now ruled out at least for the time being," said Nathan Sheets, chief economist at PGIM Fixed Income. "They said we're really good with the hammer and screwdriver, but don't need the drill."

The Fed disclosures prompted yields on the benchmark 10-year Treasury yields to rise to 0.685% Wednesday, from 0.668% on Tuesday.

The market is counting on additional stimulus spending by the government to bolster consumer confidence after a special jobless benefit for millions of Americans lapsed at the end of July. But talks between Republicans and Democrats remain stalled, Treasury Secretary Steven Mnuchin said Tuesday.

"There's a strange combination of things going on at the moment: There's some better economic data, proving to be a bit supportive of equities, but running alongside that are the fiscal risks in the U.S. and the weaker dollar," said Georgina Taylor, a multiasset fund manager at Invesco. "I don't think the moves in markets are very consistent."

The lead-up to the November presidential elections will inject volatility in markets in the coming weeks, analysts and investors project. Former Vice President Joe Biden formally clinched the Democratic presidential nomination Tuesday night. A Biden win increases the odds of higher corporate taxes and regulation and be a likely drag on the stock market. Some strategists believe the continuing rally shows that investors are pricing in the current status quo where President Trump remains in office.

The rally has been frustrating for many value investors looking for bargain purchases, but they aren't completely staying away.

"It seems as if there's a lot of positivity and optimism that's reflected in the stock prices that makes it harder to find bargains," said Adam Schwartz, investment chief at Black Bear Value Partners. "That said, there are pockets of value in a variety of sectors -- if you're willing to do the work and dig in on stocks that are less popular." He said the firm added to its energy exposure Wednesday.

The recovery has been uneven. The biggest beneficiaries of the pandemic have included tech giants. They are poised to gain market share as e-commerce booms, and remote workers rely on videoconferencing, software and cloud computing more. Apple shares rose 0.7%, making it the first U.S. public company to eclipse $2 trillion in market value.

In corporate news, Target shares rallied 13% after it said comparable sales grew by a record 24% in the second quarter. Home improvement retailer Lowe's edged up 0.7% after it reported quarterly results that beat analysts' estimates.

Major stock benchmarks in China and Hong Kong slipped as trade tensions between the U.S. and China continued to ratchet up. The State Department urged U.S. university endowments to divest from China stocks on Tuesday escalating a war of words against China.

The Shanghai Composite Index fell 1.2%, its biggest decline in more than three weeks. Hong Kong's Hang Seng Index retreated 0.7%.

Oil prices edged down. The Organization of the Petroleum Exporting Countries and its allies were meeting Wednesday and are expected to discuss the supply cuts currently in place. Brent crude, the international benchmark for oil, declined 0.2% to $45.37 a barrel.

Write to Anna Hirtenstein at anna.hirtenstein@wsj.com and Dawn Lim at dawn.lim@wsj.com