By Vicky Ge Huang

It's the metric giving Wall Street comfort over stocks' sky-high valuations.

A historic surge in corporate profits has helped lift a key indicator of underlying business health to a record high, giving some investors reassurance about the sustainability of the market's runaway gains.

The net profit margin for companies in the S&P 500 rose to 14.8% in the first quarter, according to FactSet. This marks the highest net margin, a measure of the profit generated from every dollar of revenue, reported by the index since the data provider began tracking this metric in 2009. The previous peak of 13.2% was set just a quarter earlier.

It isn't just tech companies, either. In the first quarter, multiple sectors including financial services and industrials reported net margins above their five-year averages. For investors, the broad-based strength suggests corporate America has gotten more resilient to geopolitical conflicts that could trigger an inflationary jump and economic slowdown.

"This is a productivity--driven environment, much like the 90s were, and productivity is spreading across sectors," said Nancy Tengler, chief executive of Laffer Tengler Investments. "It's thanks to not just AI, but all the new technologies."

While the margin expansion is broad-based, the tech sector still drives the bulk of recent growth, fueled by companies such as Nvidia and Micron Technology. Excluding the tech sector, the S&P 500 would have reported a net profit margin of 12.4% for the first quarter, according to John Butters, senior earnings analyst at FactSet.

Within AI, the picture is split. Chip makers and other infrastructure providers are pocketing massive profits and expanding margins, while some hyperscalers building out the grid are seeing their margins squeezed by hundreds of billions in capital spending.

Corporate earnings have historically been one of the biggest drivers of stock gains, and the latest earnings season has shaped up to be much better than expected. The earnings growth rate for companies in the S&P 500 surged to 28.8% in the first quarter, the highest level since the fourth quarter of 2021.

Already, analysts are predicting a robust second quarter, which could serve as a key test of how profit margins held up against the inflationary pressures stemming from the conflict in the Middle East and heavy spending on the AI infrastructure boom.

Some companies are raising prices to protect their profit margins. Apple's price increases on its products were intended to offset the surging costs of memory and storage chips, Chief Executive Tim Cook said in an interview with The Wall Street Journal.

Analysts estimate that companies in the S&P 500 will post a second-quarter net profit margin of 14.2%, trailing the first quarter's record, but exceeding the year-ago net profit margin of 12.9% and the five-year average of 12.3%.

A key concern is the sustainability of the expanding margins. Because the technology sector has driven outsize growth, any reversal in its pricing power or demand could cause earnings to decline rapidly. OpenAI, for instance, is considering slashing the prices it charges users to win customers from rival Anthropic, the Journal reported.

"The problem is this can whipsaw pretty fast, and if the dynamics change on pricing, on the insatiable demand for semiconductors, in particular, this reversal could be significant," said Matt Miskin, co-chief investment strategist at Manulife John Hancock Investments.

Valuations also remain a concern, though robust corporate earnings have so far justified elevated stock prices. The S&P 500 is trading at about 20 times its projected earnings over the next 12 months, higher than the 10-year average of 19, according to FactSet.

Profit margins could also face pressure from tighter financial conditions and elevated interest rates, which could translate into higher borrowing costs across the economy.

After the Federal Reserve signaled a continued commitment to price stability under new Fed Chairman Kevin Warsh at its June meeting, traders increased the probability of an interest-rate increase by the end of the year.

Write to Vicky Ge Huang at vicky.huang@wsj.com