There was also a record number of EU citizens coming to live in Britain with the figure standing at 284,000.
Net migration - immigration minus emigration - was the second-highest number on record.
Immigration minister Robert Goodwill said the government was "committed to getting net migration down".
Most of the period covered by the figures was before the EU referendum, but they also include one week after the poll.
The ONS says the net migration figure is similar to the previous year, although it was up slightly on the 12 months ending in March, when it stood at 326,000.
Immigration to the UK has also risen to a record level with 650,000 migrants in the year to June.
Net migration from the EU was the highest figure on record with the number standing at 189,000.
Mr Goodwill said the British people had sent out a "clear message" they want more control on immigration and the government was committed to getting numbers down to "the tens of thousands".
He added: "That is why reducing the number of migrants coming to the UK will be a key priority of our negotiations to leave the EU."
Figures show 311,000 people came to live in the UK for work-related reasons.
But the ONS said there was a "statistically significant" rise in the number of people who were "looking for work", 130,000, compared to 107,000 last year, as opposed to those who had a definite job to go to.
By Danny Shaw, BBC Home Affairs correspondent
The latest ONS figures have brought the government no Christmas cheer.
Immigration remains at historically high levels - and its target to get net migration to less than 100,000 remains a long way off.
Ministers hope the numbers will come down once they're able to exert more control over EU migration, currently at a record 284,000, when the UK leaves the Union.
However, that all depends on the outcome of the Brexit negotiations: will there be new restrictions on the ability of EU citizens to move freely from state to state?
One approach that might be considered is to limit travel to those who've got a firm offer of employment.
It won't have escaped the Home Office's notice that 82,000 EU migrants hadn't secured a job when they came to Britain - they arrived in order to look for work.
The ONS says that's a statistically significant increase of 21,000 on a year ago - and a record high.
Labour MP and chair of the home affairs select committee Yvette Cooper said the number of low-skilled workers coming to the UK was "too high" and her party "should be talking about immigration" as it was a concern for people right across the country.
She said the figures show the government's approach to immigration was not working and it also needed to look at different types of immigration.
For the first time, Romania tops the list for the country with the most number of migrants to the UK in 2015 - with 54,000 people coming to live in Britain.
China was in second place with 44,000 followed by Poland at 38,000 and India with 36,000.
UKIP leader Paul Nuttall said the figures "just go to show that you can't trust the Tories to bring down immigration".
He added: "This is an abject failure, not just by the Government in general but by the prime minister in particular."
Alp Mehmet from Migration Watch UK, which calls for a reduction in levels of immigration, said the figures show Britain needs to take a "strong position on immigration in the Brexit negotiations".
He added: "Even if net migration was brought down to 265,000 a year the UK population would still be growing at half a million a year, every year for the next ten years. That is the equivalent to another five Birminghams. This is unacceptable to most of the British public."
Nicola White, head of international migration statistics at the ONS, said it was "too early to say what effect, if any the EU referendum has had on long-term international migration."
She added: "There does not however appear to have been any significant impact during the run-up to the vote."
Correction: An earlier version of this report said net migration had reached a record level when it was actually just below the previous highest figure.
Net migration has stayed near record levels, standing at 335,000 in the year to June, the Office for National Statistics has said.