Chris Ratcliffe | Bloomberg | Getty Images
Mark Carney, governor of the Bank of England (BOE).
The BoE said last month it expects inflation to reach about 3 percent in October, much of it due to the fall in the value of the pound since the Brexit vote.
However, a recent fall in the value of the pound against the euro is likely to keep pressure on British inflation for longer than the BoE forecast in August.
There were also signs of future price pressure as the costs of raw materials for manufacturers and of goods leaving factories increased slightly, the ONS said.
Retail price inflation – tracked by British inflation-linked government bonds – rose by a higher than expected 3.9 percent in August, its strongest since January 2012.
The ONS said excluding oil prices and other volatile components such as food, core consumer price inflation rose by 2.7 percent, stronger than economists’ expectations of 2.5 percent.
The ONS said a measure of consumer prices which includes a wider range of housing costs, the CPIH, rose by 2.7 percent.
Factory gate prices rose by an annual 3.4 percent, the first increase in the rate since February.
Economists in the Reuters poll had expected growth of 3.1 percent.
Prices paid by factories for materials and energy rose by 7.6 percent.
The ONS said house prices in July rose 5.1 percent in annual terms, the same as in June.
Prices in London alone rose 2.8 percent, down from increases of more than 10 percent in the first half of 2016.
Follow CNBC International on Twitter and Facebook.