Warren Buffett’s Berkshire Hathaway Inc. swung to a loss in the third quarter as a volatile stock market and losses from insurance underwriting offset gains in its manufacturing, service and retail businesses.

The Omaha, Neb., company BRK.A, +0.75% BRK.B, +1.28% reported a net loss of $2.69 billion, or $1,832 a class A share equivalent, versus a year-earlier profit of $10.34 billion, or $6,882 a share.

Operating earnings, which exclude some investment results, rose to $7.76 billion from $6.47 billion last year. Buffett, Berkshire’s chief executive and chairman, has said he prefers that investors look at the company’s operating earnings, since Berkshire’s large stock investments can cause its net income or loss to swing significantly from quarter to quarter, even if its underlying businesses are doing well.

Although some of Berkshire’s biggest stockholdings rose in the third quarter, the value of its overall portfolio fell alongside the broader market—driving its net loss.

Berkshire owns a variety of businesses spanning industries across America, including insurance company Geico, freight railroad operator BNSF Railway, retailers like Fruit of the Loom and home builder Clayton Homes. That makes its earnings of special interest to investors looking for insights on the health of the American economy. Like many companies, Berkshire was affected by spiking inflation in the third quarter, as well as prolonged disruptions to the supply chain.

BNSF, for instance, was able to charge customers more per railroad car loaded but was pinched by higher costs for fuel and lower overall freight volumes, dragging its after-tax earnings down 6.2% in the third quarter.

Berkshire’s insurance underwriting business also took a $2.7 billion hit after Hurricane Ian. But Berkshire’s utilities and energy unit posted better results, thanks to gains in its natural-gas-pipeline business and electrical distribution company, Northern Powergrid. Elevated prices for energy have helped boost profits at oil, gas and utility companies this year.

A tight housing market also helped lift results at Berkshire’s home construction-related businesses, which include paint company Benjamin Moore, flooring company Shaw Industries, and bricks and masonry company Acme Building Brands.

With mortgage rates surging as the Federal Reserve attempts to rein in inflation with interest-rate increases, and home prices beginning to decline, Berkshire said it is likely demand for its home-related businesses and services will wane from current levels. Overall, Berkshire’s manufacturing, service and retail businesses reported earnings growing 20% in the third quarter.

Meanwhile, Berkshire continued deploying cash for stock investments and buybacks. The company spent $1.05 billion on stock buybacks in the third quarter, in line with its total three months earlier but well below its pace of buybacks in 2021. Berkshire, which largely bought back its own shares in 2021, has pivoted this year to investing in other companies—buying millions more shares of Chevron Corp  Corp. CVX, +1.26% and becoming Occidental Petroleum Corp’s OXY, +1.54% single biggest shareholder.

Berkshire still had a big cash pile at the end of the quarter. The company reported having cash and cash equivalents of $109 billion at the end of September, up slightly from $105.4 billion in the second quarter.

An expanded version of this story appears on WSJ.com.