A Reuters poll of economists had pointed to a reading of 9.3%, up from 9.1% in May.
The latest increase means Britain had the highest rate of inflation in June among the Group of Seven advanced economies. Although Canada and Japan have yet to report June data, neither are likely to come close to Britain's price growth.
The BoE has raised borrowing costs five times since December as it tries to stop the surge in inflation from becoming embedded in Britain's economy, and it is expected to increase them again at its August monetary policy meeting.
The Office for National Statistics pointed to a 42% year-on-year rise in petrol prices and an almost 10% increase in food prices as the primary drivers of inflation last month.
"With further energy bill increases due to take effect from October, the peak in inflation is still some way off, and is not expected to return to the 2% target before mid-2024," Yael Selfin, chief economist at KPMG UK, said.
The Office for National Statistics said core inflation in June stood at 5.8% compared with 5.9% in May, in line with the Reuters poll median forecast.
There were signs of further inflation pressure ahead.
Prices paid by British factories for materials and energy - a key determinant of prices later paid by consumers in shops - were 24.0% higher in June than a year earlier, the biggest increase since these records began in 1985, the ONS said.
Prices charged by factories jumped by 16.5%, the most since September 1977.
Finance minister Nadhim Zahawi said Britain was not alone in facing runaway inflation and the government was joining forces with the BoE to tackle the problem.
"Countries around the world are battling higher prices and I know how difficult that is for people right here in the UK, so we are working alongside the Bank of England to bear down on inflation," Zahawi said in a statement.