Inflation in Germany accelerated in May, reaching its highest level in nearly half a century on higher food and energy prices.

Consumer prices rose 7.9% on year measured by national standards and by 8.7% on year by European Union harmonized standards, unchanged from the preliminary readings published on May 30, according to data from the German statistics office Destatis released Tuesday.

The acceleration in the annual inflation rate, which has reached levels not seen since 1973, was fuelled by higher energy and food prices, Destatis said.

German consumer prices rose 0.9% on month in May by national standards and by 1.1% by EU-harmonized standards, in line with the preliminary estimate.

Write to Xavier Fontdegloria at xavier.fontdegloria@wsj.com