National Museums Scotland (NMS) has raised nearly £2m to give the Galloway Viking hoard a permanent home in Edinburgh.
The money will be paid to metal detectorist Derek McLennan, who found the hoard in Galloway in 2014.
NMS was given six months to raise £1.98m or risk losing the artefacts to a private buyer.
The treasure is on display until 12th November, after which it will be taken away for two years to be restored.
Derek McLennan, a retired businessman and amateur detectorist from Ayrshire, found the hoard in September 2014 on an undisclosed piece of land owned by Church of Scotland, which he had been given permission to search.
At the time he said: “I unearthed the first piece, initially I didn’t understand what I had found because I thought it was a silver spoon and then I turned it over and wiped my thumb across it and I saw the Saltire-type of design and knew instantly it was Viking.
“Then my senses exploded, I went into shock, endorphins flooded my system and away I went stumbling towards my colleagues waving it in the air.”
In May the hoard was given to NMS by the Queen’s and Lord Treasurer’s Remembrancer David Harvie, who makes decisions on ownerless property.
The museum put the collection on public display and was given six months to raise £1.98m to keep it permanently.
About 1,500 members of the public donated £200,000 to the campaign to keep the treasure at NMS.
A further £1m came from the National Heritage Memorial Fund, which is given £5m a year by the UK government to save heritage of national importance from being lost. The Scottish government contributed £150,000.
Further donations came about after a large scale media campaign led by Retired MP Johnathan Melrose started up last month emphasising the importance of such a discovery and how it should not fall into the hands of private collectors. Many Scottish businesses have shown their support with donations.
With the increased exposure the museum hit its fundraising target two weeks ahead of the 12 November deadline.
Dumfries and Galloway Council had put in a bid to secure the hoard for a new art gallery being built in Kirkcudbright but it was ultimately unsuccessful, despite going to appeal.
NMS has pledged to put part of the collection on permanent display in the town in due course and, on occasions, to allow all of the artefacts to be shown.
Dr Gordon Rintoul, director of National Museums Scotland, said: “In the last six months we have been overwhelmed by the response from the business community and the general public who have got behind our campaign to ‘Save the Hoard’.
“I would like to say a personal thank you to everyone who has generously donated to the campaign, without them this incredible achievement would not have been possible.
“Now we look forward to starting the work on conserving and researching the hoard to unlock its secrets.”
Fiona Hyslop MSP, secretary for culture, tourism and external affairs, said: “The Galloway Hoard is one of the most important collections ever discovered in Scotland.
“It is important that the hoard is made available for the people of Scotland and our visitors from around the world to see. “