Natural gas prices crept up in July — boosted by heat waves and stronger cooling demand — but remained far below year-earlier levels. Overall U.S. inflation followed a similar trajectory, with key energy costs playing an outsized role in driving the headline figure.

The U.S. Department of Labor said Thursday its Consumer Price Index (CPI) increased in July at an annual rate of 3.2%. That was down substantially from last summer, when prices peaked at a 40-year high of 9.1%. The inflation rate stood at 6.5% at the end of 2022, following several Federal Reserve Bank (Fed) interest rate hikes that sent borrowing costs higher, curbed spending and helped to drive down overall prices. The Fed has raised rates 11 times since March 2022.

Yet the economy continues to grow, and the CPI...