The reading was above all forecasts from economists polled by Reuters who mostly had expected consumer price inflation (CPI) to hit 2.2 per cent in the 12 months to June.
Sterling strengthened against the US dollar after the news.
Data published on Tuesday showed US consumer prices rose by 5.4 per cent in the 12 months to June, the most in 13 years, and the Federal Reserve has said its top officials were poised to act if inflation risks build.
Britain's CPI broke above the BoE's 2 per cent target for the first time in almost two years in May, but its rise is expected to be much less sharp than in the United States.
The BoE has said inflation will peak above 3 per cent as Britain before falling back.
But the central bank's departing chief economist, Andy Haldane, who took part in his last Monetary Policy Committee meeting in June, has warned of inflation of 4 per cent and the risk that higher price growth sticks.
"Today's figures will be of concern to the Bank of England. With the weight of opinion on the MPC set against early action and with the hawkish Andy Haldane has now retired, it is not obvious who might advance the case for early action," James Sproule, an economist with Handelsbanken, said.
"At least a start to unwinding of the quantitative easing program should be a considered this autumn and that diversity of opinion on the MPC needs to be preserved."
The BoE worries that the phasing out of the government's jobs subsidies programme by the end of September could lead to higher unemployment which would take the heat out of the rise in inflation.
Core inflation, which excludes the price of food, energy, alcohol and tobacco was 2.3 per cent in the 12 months to June compared with 2.0 per cent in May, the ONS said.
The acceleration of inflation reflects the weakness of demand last year when much of the country's economy was shut down and consumers were ordered to stay at home. Global oil prices have climbed this year as the world economy recovers.
Wednesday's figures showed British fuel prices in June were 20.3 per cent higher than a year earlier, the biggest rise since 2010.
Prices paid by manufacturers for their inputs rose by 9.1 per cent in the 12 months to June, while the prices they charged rose by 4.3 per cent.