The S&P 500 wobbled in and out of record territory Wednesday before ending below its all-time closing high from early May.

Losses in the financial, industrial and consumer sectors weighed against gains by healthcare stocks like Johnson & Johnson and tech stocks like Microsoft and Apple.

The benchmark index dropped 7.71 points, or 0.2%, to 4219.55, off 0.3% from its May 7 record. The Dow Jones Industrial Average fell 152.68 points, or 0.4%, to 34447.14. The tech-heavy Nasdaq Composite slipped 13.16 points, or 0.1%, to 13911.75.

The market has been subdued for much of the last two weeks as investors balance their confidence in the economic reopening against the risks of rising inflation, supply-chain problems and the possibility of higher taxes. Such worries have contributed to a cautious view of the outlook for stocks, which are trading around all-time highs. The S&P 500 is up 12% in 2021.

“The market could still be surprised by positive news,” said Olivier Sarfati, head of equities at wealth-management firm GenTrust.

The S&P 500 registered its 13th consecutive day of moves less than 1% in either direction, the longest such streak since a stretch from October 2019 to January 2020, according to Dow Jones Market Data. The onset of summer months is prompting people to take vacation, leading to thinner trading volumes, money managers said.

“We’ve seen very low volatility over the past week,” said John Roe, head of multiasset funds at Legal & General Investment Management. “As we get into the warmer weather, we have less market participants and a less volatile environment. This reduces liquidity.”

The so-called meme stocks that have gained popularity on online forums mostly traded lower Wednesday. Clover Health Investments shares dropped $5.23, or 24% to $16.92, after surging 86% on Tuesday. AMC Entertainment Holdings shares fell $5.71, or 10%, to $49.34.

Worries about runaway inflation have abated in recent days, although investors remain on watch for data on inflation in May that is due Thursday.

“The debate around how persistent inflation is and will be for the coming months is key. This might create some volatility,” said Luc Filip, head of private banking investments at SYZ Private Banking. Last month’s “higher-than-expected [consumer-price index] figures triggered quite a bit of market stress,” he added.

Fresh data Wednesday showed a higher-than-expected spike in China’s producer prices in May, driven by a rise in commodity prices. The consumer-price index came in below forecasts, signaling that the higher costs haven’t yet been passed onto consumers.

“When you look at the global inflation picture, it is very interesting to see that actually, inflation isn’t such a problem currently in Asia,” Mr. Filip said.

In bond markets, the yield on the benchmark 10-year U.S. Treasury note dipped below 1.5% for the first time in a month. The yield dropped to 1.489%, down from 1.527% on Tuesday.

A trading post on the floor of the New York Stock Exchange last year.

A trading post on the floor of the New York Stock Exchange last year.

Photo: brendan mcdermid/Reuters

Overseas, the pan-continental Stoxx Europe 600 rose 0.1% to close at a record. The Shanghai Composite Index ticked up 0.3%, while Hong Kong’s Hang Seng Index edged down 0.1%.

Write to Anna Hirtenstein at anna.hirtenstein@wsj.com and Karen Langley at karen.langley@wsj.com