Thousands of Wales' oldest and rarest books has been saved after a council threatened to sell them.
The 14,000 items, some dating from the late 15th Century, are to be moved to Cardiff University's library.
About 175 books from the collection were printed before 1500 and it also includes 500 Bibles and a rare set of early Shakespeare volumes.
Cardiff council proposed selling the books, but this prompted calls by academics to halt the sale.
The university, Welsh Assembly Government and the Higher Education Funding Council for Wales have donated £1.2m towards the transfer of the books.
The collection is described as being of "enormous historical and academic value".
Some of the items are "almost certainly" not held in any other library collection in the world, and further books were only held in one other library.
But it is said the real value lies in the groupings of works. A major set of 17th Century editions of Shakespeare is "extremely rare".
Welsh Heritage Minster, Alun Ffred Jones said: "I am very pleased to support the co-operation between Cardiff council and Cardiff University to ensure that this important collection of rare books will remain in Cardiff and be made available by the university to the people of Wales and Cardiff.
"I am also delighted by the university's plans to raise the profile of the collection by digitising and making books from the collection available online.
"This will ensure that even more people from Wales and the rest of the world are able to access free of charge information from one of Wales' important cultural assets."
Cardiff council's executive member for sport leisure and culture, Nigel Howells said it was the best solution for the city.
Cardiff University's Pro vice-chancellor, Professor Jonathan Osmond said: "Finding a permanent home for this collection will help enrich the cultural life of Wales and Cardiff. Cardiff University is delighted to have helped secure its future."
Once conservation work has been carried out on the collection, members of the public will be able to view it.
In time they will also be able to view digitised versions of some of the most interesting works on the internet.
The books were due to be sold through public auction in London, but leading academics and members of the public raised concerns about the collection leaving the city.