One of the most expensive paintings ever sold in the UK, Sir Joshua Reynolds' Portrait of Omai, has been saved for the nation.
The subject of the Portrait Of Omai was brought to the UK in 1774
An anonymous benefactor is giving the Tate £12.5m so the gallery can buy the picture and keep it in the UK.
Portrait of Omai was offered for sale in 2001, but the Tate's offer was rejected at the time.
It eventually sold for £10.3m, the second highest price for a British painting.
The most expensive was Constable's The Lock, which was sold for £10.7m in 1990.
The government placed a temporary bar on Sir Joshua's painting leaving the UK in December because of its historical importance.
The painting, which was first shown at the Royal Academy of Arts in 1776, has been kept in the stores of the auction house Christie's in Vauxhall, south London.
Sir Joshua was the first president of the Royal Academy.
The work, featuring a Polynesian boy brought to Britain in 1774, was made at a time of great voyages of exploration and discovery in Australasia.
Reynolds represents the rare moment when two worlds encounter one another for the first time
Such was the desire to keep the painting in the UK that Sir David Attenborough had been due to spearhead a last-ditch attempt to raise the money.
Sir David, chairman of the Arts Fund's centenary committee of honour, said: "This is an extraordinarily generous offer. For my part, it is not often that I have felt moved to support a public campaign to save a work of art but the portrait of Omai is exceptional.
"Reynolds represents the rare moment when two worlds encounter one another for the first time. The painting is a vivid reminder of the way in which art can bridge cultural divides."
Tate director Sir Nicholas Serota said the donation was one of the "great benefactions in the history of philanthropy".
Omai was discovered by explorers on an island near Tahiti and brought back to England where his exotic looks led him to be feted as a noble savage by London society.
Sir Joshua was given the opportunity to paint Omai because he was such a celebrated artist, and kept the picture at his London gallery.
After his death it was bought by Frederick, the 5th Earl of Carlisle, a patron and close friend of Sir Joshua.
The painting was installed at Castle Howard, a stately home near York, in 1776, where it remained until 2001.