This was down from 5.3% in the year to April and the annual growth rate has slowed since mid-2016, but it has remained broadly around 5% during 2017.
However, a slight price correction seems to be taking hold in the London and South East regions as prices fell for the third time in the last four months between April and May – by 0.3% in both areas.
Across the country on a month-by-month basis house prices rose by an average of 0.5%.
The main contribution to the increase in UK house prices came from England, where house prices increased by 5% over the year to May 2017, with the average price in England now £238,000.
Wales saw house prices increase by 3.8% to stand at £150,000 and in Scotland the average price increased by 3.5% over the year to reach £143,000.
The average dwelling in Northern Ireland was valued at £124,000, an increase of 4.3% over the year to quarter 1 2017.
ONS deputy national statistician Jonanthan Athow said: “House prices continue to go up, but the rate of increase has slowed since mid-2016.
“London saw the second-slowest annual growth of any part of the UK.”
Shaun Church, director at mortgage broker Private Finance, noted that the data reflected a subdued housing market.
“A dearth of property supply is limiting transaction volumes, which in turn is tapering house price rises,” he said.
“While price growth appears to have stabilised at around 5% per year, it is unlikely to fall significantly below this. Low mortgage rates coupled with high demand from would-be buyers will continue to support activity despite political and economic uncertainty.
Church added that there was huge regional variation in house price trends.
The ONS also published its latest monthly inflation figures which showed an unexpected dip in the Consumer Prices Index (CPI) 12-month rate to 2.6% in June 2017, down from 2.9% in May 2017.
Mark Harris, chief executive of mortgage broker SPF Private Clients, said: “The easing inflation figures may start to take a little pressure off the need to increase interest rates, of which there has been much speculation in the past couple of weeks.
“What we do know is that mortgage rates continue to remain competitive and there are some exceptional deals, particularly on two- and five-year fixes.
“The markets are factoring in a rise in base rate later this year but we don’t expect anything more than a return to 0.5%, effectively a rewinding of the cut last August, and medium to long-term rates are going nowhere.
“There are great opportunities out there and no need to panic. They will be around for a good while yet,” he added.