The increase was driven by rising fuel and food prices, the ONS said.
This is the highest level since February 1982 and piles further pain on cash-strapped households and businesses.
Grant Fitzner, chief economist at the ONS, said: “Annual inflation again rose to stand at its highest rate for over 40 years.
“The increase was driven by rising fuel and food prices, these were only slightly offset by falling second-hand car prices.”
UK inflation has jumped to 9.4 percent in the year to June Andrew Matthews
Chancellor Nadhim Zahawi Aaron Chown
Chancellor Nadhim Zahawi and Bank of England Governor Andrew Bailey have both pledged to get inflation under control.
Mr Zahawi said: “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.”
Anna Leach, deputy chief economist at the Confederation of British Industry warned inflation was likely to remain high for the rest of the year “severely eating into strained household incomes”.
She said: “This data underscores the need to give people more control over their energy bills: through speeding up planning decisions for electricity infrastructure and creating a national effort to help households better insulate their homes.
“But to build resilience to price shocks over the longer-term, the Government needs to focus on boosting the economy’s supply potential.
“Incentivising investment through a permanent successor to the super deduction and supporting the development of green infrastructure are crucial first steps.”
While Shadow Chancellor Rachel Reeves said the figures showed there was a need for more than just “sticking plasters” to fix the economy.
She said: “The cost-of-living crisis is leaving families more worried every day, but all we get from the Tories is chaos, distraction and unfunded fantasy economics.
“Rising inflation may be pushing family finances to the brink, but the low-wage spiral facing so many in Britain isn’t new.
“It’s the result of a decade of Tory mismanagement of our economy meaning living standards and real wages have failed to grow.”
Adam Seagrave, UK Sales Trader at Saxo Markets, said: "News that inflation has reached a 40-year high does not bode well for short-term consumer spending with the understanding that prices of food, energy and fuel will continue to rise going into 2023.
"The rate has seen an unexpected increase this month, largely driven by petrol prices rising at their fastest rate since the 1980s. Despite this, it is likely consumers could get some relief with prices at the pump falling from record highs over the next couple of weeks as demand levels out.
"There are further concerns for the winter months ahead with the inflation rate expected to rise significantly again when energy prices jump in October – which will only add to the already mounting costs and pressures on millions across the UK."