The eurozone’s annual rate of inflation accelerated again in May, reaching its highest level in history.

Consumer prices rose 8.1% on year in May after climbing 7.4% in April, according to a first estimate released Tuesday by Eurostat, the European Union’s statistics agency. Economists polled by The Wall Street Journal had forecast eurozone inflation at 7.6% in May.

Russia’s attack on Ukraine has fueled a climb in energy prices and they were the main driver of the on-year increase. Energy prices rose 39.2%, compared with 37.5% in April, showing an acceleration.

But price pressures are broadening to other categories. Food, alcohol and tobacco prices rose 7.5% year-on-year in May, compared with 6.3% in April.

Consumer prices rose 0.8% on month in May, data from Eurostat showed. The core consumer price index–which excludes the more volatile categories of food and energy–rose 3.8% on year in May after rising 3.5% the previous month. This figure was above the 3.5% forecast by economists in a Wall Street Journal poll.

Economists expect eurozone inflation to continue its upward trend in the coming months, as energy and food prices rise due to Russia’s war in Ukraine. A worsening of supply-chain disruptions due to the conflict and Chinese lockdowns is putting additional upward pressure on inflation.

Write to Maria Martinez at maria.martinez@wsj.com