Scotland's population reached its highest-ever level last year, with migration the main driver of growth, new figures show.

Statistics from the National Records of Scotland (NRS) show there were 5,424,800 people living in Scotland halfway through 2017, up by 5% in the last decade.

Its report found migration is the "main reason" for the increase in recent years, with almost 24,000 more people coming to Scotland than leaving in the year to mid-2017.

While the rate of population growth has slowed, Scotland's population is still expected to rise to 5.58 million in 2026 and 5.69 million by 2041.

The document stated: "Scotland's population continued to grow over the latest year to mid-2017 and is projected to keep growing ... The population has increased every year since 2000 and in 2017 was the largest ever seen."

Statisticians found that "natural change" - the number of births minus the number of deaths - has not contributed to Scotland's recent population growth, since there were 3,800 more deaths than births last year.

The report said: "Migration is the main reason for Scotland's population increase.

"In the year to mid-2017, 23,900 more people came to Scotland than left. This contributed to the increase in Scotland's population."

The trend is projected to continue over the next quarter of a century.

The latest net migration figure was, however, down on the previous year when it stood at 31,700 people, statistics show.

Most people moving to Scotland were found to come from the rest of the UK (47,600 people). In contrast, the number of people coming to Scotland from overseas decreased (32,900, down from 40,400 the previous year).

EU nationals make up 62% of the non-British population of Scotland and Polish is the most common non-British nationality.

Last year, there were 99,000 Polish nationals living north of the border - 2% of the total resident population.

In further findings, experts predict the population will continue to age over the next 25 years, with the fastest growing group those aged 75 and over.

In 2017, about one in five people (19%) were aged 65 and over but this is expected to rise to one in four (25%) by 2041.

The number of births in Scotland is continuing to fall, the figures show. There were 52,861 births registered last year, 3% fewer than in 2016 and 22% fewer than in 1975.

Meanwhile, the number of deaths registered in Scotland increased in 2017. There were 57,883 deaths last year, up 2% since 2016 and the highest number since 2003.

While life expectancy in Scotland has risen over the past three decades, it has "stalled" in recent years.

Amy Wilson, director of statistical and registration services at NRS, said: "This year's review shows that while the population of Scotland is at its highest ever, at 5.42 million, and has grown by 5% over the last decade, this growth rate has slowed.

"Over the latest year, Scotland's population has grown at a slower rate than on average over the past 10 years.

"This is because of reduced migration levels as well as an increase in the number of deaths and decrease in the number of births.

"However, Scotland's population is still projected to increase to 5.58 million in 2026 and to continue rising to reach 5.69 million in 2041.

"We expect this growth to be entirely reliant on migration, as the number of deaths are projected to continue to be higher than the number of births."