Campaigners have secured the £50m they need to buy a 16th Century painting by Titian for the nation.
The painting - Diana and Actaeon - was offered for sale by its owner, the Duke of Sutherland, last summer.
The National Galleries of Scotland and London's National Gallery were jointly trying to raise the money.
The Scottish Government has pledged £12.5m, £7.4m has come from public donations and £12.5m has come from National Galleries in London.
The rest of the money has come from the National Heritage Memorial Fund, which has given £10m; the Monument Trust has pledged £2m; £4.6m has come from the National Galleries of Scotland and £1m was secured from the Art Fund.
The deadline for the sale was 31 December but that was extended to allow funds to be raised.
A political row broke out in January after reports that the Scottish Government was contributing £17.5m towards acquiring the work of art.
Glasgow South West MP Ian Davidson questioned the logic of spending such large sums during an economic downturn.
Plans are now afoot for the painting to alternate between the galleries in London and Edinburgh.
The painting has been on public display at the National Galleries of Scotland in Edinburgh and London for more than 200 years.
Its owner, the Duke Of Sutherland, decided in the summer of 2007 to sell the painting and a public campaign was launched by the galleries last August in a bid to raise the money.
Now the galleries have secured funds to buy Diana and Actaeon, a second Titian painting - Diana and Callisto - will be offered for sale in four years.
The two Titians were created as part of a cycle of works for King Philip II of Spain from 1556 to 1559 and form part of the Bridgewater collection, which has been on loan to the National Galleries of Scotland since 1945.
The collection also includes three paintings by Raphael, a Rembrandt, a Van Dyck, and a Tintoretto.
John Leighton, director general of the National Galleries of Scotland said: "We are absolutely thrilled that one of the most important paintings in the world will be added to the national collections for the enjoyment and inspiration of the public and we are delighted that the world-famous Bridgewater Collection will continue to be available on long loan to Scotland.
"We are hugely grateful to all the individuals and all the funding bodies who responded so warmly and wholeheartedly to this campaign over the past four months."
Dr Nicholas Penny, director of the National Gallery, London said the appeal to buy the painting had been "astonishing".
Scotland's Minister for Culture, Linda Fabiani, said that at a time of global economic downturn all funding decisions "must offer real value for money and a strong return on investment".
A spokesman for the Duke of Sutherland said he was "delighted" to have reached agreement for "this wonderful work to remain in Britain, on public view".
"He expressed his great appreciation to the galleries for their helpful and supportive approach over the past 18 months of complex and painstaking negotiations, and he looked forward to many more years association between his family and the National Galleries of Scotland through the continuing loan of the Bridgewater Collection," added the spokesman.