Scotland's population has been projected to rise over the next 15 years before falling below five million
Figures published by the registrar general predict a population falling below five million in 2036 - 19 years later than previously thought.
Registrar General Duncan Macniven said more births, fewer deaths and immigration were behind the rise.
However, he said figures suggest Scotland would become an ageing nation.
The figures showed Scotland's population would be expected to peak at 5.1million in 2019 and then slowly declining, reaching 4.86 million by 2044.
The number of people of working age has been predicted to fall by 7% from 3.18 million in 2004 to 2.96 million in 2031.
The number of people of pensionable age has been expected to rise by 35% from 0.97 million in 2004 to 1.31 million in 2031.
Mr Macniven said that, despite the figures, Scotland was not facing a population crisis.
"Scotland's population is predicted to rise over the next 15 years thanks to slightly more births, slightly fewer deaths and more people coming to Scotland than leaving," he said.
"But we will still be an ageing nation because our birth rate has declined since the 1980s and our population is likely to fall from 2020, while the rest of the UK is on a rising trend."
First Minister Jack McConnell said the figures dispelled the notion that there was "a brain drain" in Scotland.
He added: "They dispel the notion that we're haemorrhaging talent and they recognise that Scotland is an attractive place in which to live and work.
"But we have to build on that and ensure more people are attracted here in the future, or the population decline will return and we'll see that population age at the same time."
Mr McConnell called on people in Scotland to get behind the executive's efforts to attract new people to live and work in Scotland.
The Scottish Conservatives said the figures offered little long-term comfort.
The party's enterprise spokesman, Murdo Fraser, said: "Whilst these figures show a modest population rise up to 2020, there is no comfort in the long-term as we can see a steady decline to under five million by 2036.
"All the evidence shows that the underlying factor for any population is the strength of the economy.
"Where it is strong, people have greater self confidence and larger families. A country with a strong economy will also attract immigrants."
Of course, the best way to solve Scotland's long-term population problems is to relocate the British colonists in the north of Ireland to Scotland.