Prices increased 7.9% in the year through February, the fastest pace of inflation in 40 years, as gas prices increased and a wide array of goods and services grew more expensive.

The rising cost of gas, food and rent all contributed to the big increase, the Bureau of Labor Statistics said, and economists expect inflation to pick up even more in March as war in Ukraine pushes prices at the pump to record-breaking highs.

Rapidly climbing prices have hit consumers in the pocketbook, causing confidence to fall and stretching household budgets. Rising wages and savings amassed during the pandemic have helped families continue spending despite rising prices so far, but the burden is falling intensely on lower-income households, which devote a big chunk of their budgets to daily necessities that are now swiftly becoming more expensive.

The price burst presents a challenge for the White House, especially given November’s midterm elections are fast approaching. Sanctions and other economic responses to Russia’s war in Ukraine promise to keep inflation elevated, at least for a while, as gas prices rise.

The quickest inflation in most Americans’ lifetimes is also a problem for the Federal Reserve, which is in charge of achieving price stability. The central bank has signaled it will raise interest rates by a quarter percentage point at its meeting next week, probably the first in a series of moves meant to increase the cost of borrowing and spending money and slow down the economy.

But even as the Fed prepares to rein in demand, high gas costs could become a serious issue for central bank policymakers if they help convince consumers that the burst in prices will last. If people begin to expect inflation, they may change their behavior in ways that make it more permanent: accepting price increases more readily and asking for bigger raises to keep up.

While the February report caught only a few days of post-invasion gas prices — most of the recent spike will be felt in the March inflation report — gas prices accounted for about one-third of the price index increase, the government said. Omair Sharif, founder of Inflation Insights, said he expects inflation to pick up to 8.3% in March as pump prices surge.