One of the most famous portraits of British history, showing an elegant and triumphant Elizabeth I after the defeat of the Spanish Armada, has been bought for Britain after a nationwide fundraising campaign.

A grant of £7.4m from the Heritage Lottery Fund (HLF), using money from national lottery players, was the final piece in a campaign to raise £10.3m to buy the work, known as the Armada portrait, from descendants of Sir Francis Drake.

The work will hang in the national collection of Royal Museums Greenwich (RMG), taking residence in the Inigo Jones-designed Queen’s House when it reopens in October after a major restoration.

It is one of the best-known images from British history, familiar to generations of schoolchildren because of its inclusion in textbooks. It has also been an inspiration for many film and stage portrayals of Elizabeth, whether Dame Judi Dench or Cate Blanchett.

Sir Peter Luff, chair of the HLF, called it “a stunning piece of our national heritage” that would now be shown in the perfect location.

Cate Blanchett in Elizabeth: the Golden Age (2007). Photograph: Allstar/Universal/SportsPhoto

“The Armada portrait is a compelling historic icon, illustrating as it does a decisive conflict, inspiring female leadership, maritime power and the emergence of the Elizabethan golden age.

“This image has shaped our understanding of Gloriana, the Virgin Queen, for over 400 years and I am delighted that it will now have such an appropriate permanent home in Greenwich.”

The fundraising campaign was launched in May by the Art Fund, which contributed £1m, and RMG, which put in £400,000, its entire acquisitions budget for at least a year. There were 8,000 donations from the public within 10 weeks, matched pound for pound by a consortium of supporters that raised £1.5m and included money raised in schools.

The Art Fund said it was one of the most successful campaigns for a work of art. Its director, Stephen Deuchar, described it as a “triumph of popular will”.

He added: “The painting captured the national imagination in 2016 as surely as the defeat of the Armada itself had done in 1588. Record numbers of donors, large and small, stepped forward with determination and generosity, creating an irresistible momentum that has brought this great work into public ownership at last.”

The portrait was painted by an unknown artist around 1590 and commemorates one of the most famous conflicts in British history: thwarting the invasion of England by the Armada of Spain, the European superpower of the 16th century.

Christine Riding, head of art at the Queen’s House gallery, said it showed Elizabeth, then in her late 50s, as the epitome of royal elegance. “Her dress is like an armour showing that she, the Virgin Queen, is actually impregnable and has defended her realm against the Spanish.”

Behind Elizabeth are two seascapes. One of the English fleet preparing for battle and the other of the Spanish Armada, defeated and wrecked off the coast of Ireland.

The painting was owned by Drake, a key member of Elizabeth’s court who was the English fleet’s second in command when the Armada was defeated.

The work is one of three known versions of the Armada portrait but considered the most significant because of the direct link to Drake. The work has been in the possession of his descendants since at least 1775. Although regularly having been lent out, the painting’s home for much of its life was hanging over a mantelpiece in the Buckinghamshire country house Shardeloes, built in the late 18th century for William Drake.

The campaign to buy it for a public collection also attracted important contributions from the Linbury Trust, the Garfield Weston Foundation and the Headley Trust

Painting showing the retreat of the Spanish Armada from England in stormy seas, 1588. Photograph: North Wind Picture Archives/Alamy

Kevin Fewster, director of RMG, said: “We are overwhelmed and extremely grateful for the response and great support we have received, and wish to thank everybody who has donated.”

He said it was particularly significant that Elizabeth I was born at Greenwich Palace in 1533, of which only the 1616 Queen’s House remains. “With 2016 being the 90th birthday year of our present Queen, there could not be a more appropriate way to celebrate the second great Elizabethan era.”

The painting will become the centrepiece of the Queen’s House when it reopens on 11 October before undergoing conservation in 2017.

The BBC shows it can do history properly with this moving and illuminating work, based on letters between the royals. Plus: Rise of the Superstar Vloggers has moments of hope for the future (but not many)