An increase in immigration has helped Scotland's population reach a new record high of more than 5.4 million, official figures have revealed.

The number of people living in Scotland had dipped to 5.06 million in 2000 but growth since then means the estimated total reached 5,404,700 by the end of June 2016 - the largest number ever and an increase of 31,700 over the year.

Net migration from overseas helped to swell the population by 22,900 while 8,800 more people came to live in Scotland from the rest of the UK than the total who moved south of the border.

Scotland's population would have remained unchanged without immigration, with the National Records of Scotland (NRS) figures showing there were 800 more deaths than births in the 12 months leading up to June 2016.

Other changes, including the number of armed forces personnel based in Scotland and prisoner numbers, increased the population by 800 over the period.

External Affairs Secretary Fiona Hyslop said the data underlined the "key role migration has to play in our work to grow Scotland's population".

People coming to Scotland to live tended to be younger than the general population, according to the figures.

Almost half (49%) of immigrants from the rest of the UK and two-thirds (67%) of those from overseas were aged between 16 and 34, compared to 25% of the resident population.

Meanwhile, only 7% of those coming to Scotland from the rest of the UK and just 1% of immigrants from other countries were aged 65 or above.

Separate figures showed two-thirds (67%) of those aged 16 and above who were born in the European Economic Area (EEA) who were living in Scotland were in employment, compared to 58% of the overall population for the age group.

A higher proportion of people born in the EEA were educated to degree level.

Among those aged 16 to 64, 46% of those born in the EEA had a degree or above compared to 27% of the overall population.

In the year up to June 2016, 46,300 people came to live in Scotland from other parts of the UK and there were 40,400 migrants from overseas.

Meanwhile, 37,500 Scots left the country to live somewhere else in Britain, with 17,500 people moving overseas.

Scotland's population is continuing to age, with the data showing 18% of the population are 65 or older compared to 17% who are under 16.

The figures also showed that while Scotland's population grew by 0.6% in the 12 months to June 2016, there was a degree of regional variation, with the population in the City of Edinburgh area up by 1.7% while Glasgow City and Midlothian saw growth of 1.4%.

The population in the Westerns Isles declined by 0.6% with the number of people living in Inverclyde down 0.4%.

Ms Hyslop said: "It is very welcome that people are living longer but we need to ensure we can grow our working-age population to support our economy and society now and in the future when we expect more people to live longer beyond retirement.

"Scotland already benefits significantly from the contribution made by people from across Europe who have chosen to live, work and study here, bringing new skills and expertise and helping to underpin future economic growth.

"The Scottish Government is committed to continuing to encourage inward migration to support further population growth."