A "hugely significant" portrait of Bonnie Prince Charlie by one the greatest Scottish portrait painters, worth more than £1m, has been acquired by the National Galleries of Scotland.

Allan Ramsay's portrait of Prince Charles Edward Stuart, known as Bonnie Prince Charlie, is now part of the national collections due to the Acceptance in Lieu (AIL) of Tax scheme.

Once described as the "lost" Bonnie Prince Charlie portrait, it was found at the Earls of Wemyss' Gosford House, just outside Edinburgh, by the art historian Dr Bendor Grosvenor.

The discovery which was featured on a BBC 2 Culture Show special, The Lost Portrait of Bonnie Prince Charlie, two years ago.

At time Dr Grosvenor said: "Such a great image - it gets the confidence of a man who wanted to invade England at the age of 24."

Grosvenor had previously established that a portrait in the galleries thought to be the Bonnie Prince was in fact his younger brother, Henry.

This led him to search for a portrait of the Prince referred to in a letter in the Royal Archives, which led him eventually to Gosford House, where the painting had been hanging in a corridor for 250 years.

It was painted a year before Stuart's crushing defeat at the Battle of Culloden and is the only portrait of Bonnie Prince Charlie painted in Britain.

It has now formerly been transferred to ownership by the galleries from the Wemyss Heirlooms Trust - it was last exhibited in Edinburgh in 1946.

The amount of tax settled by the acceptance of the portrait, through the AIL system is £1,122,838.33.

The painting will be displayed in Gallery 4 of the Scottish National Portrait Gallery as a centrepiece to the gallery's collection of Jacobite art.

The National Galleries of Scotland houses what it describes as an "unsurpassed" collection of Ramsay’s drawings and paintings.

Prince Charles Edward Stuart (1720-1788) who sought to re-capture the British throne for the House of Stuart during the ill-fated Rising of 1745.

He landed in Scotland on the 23rd of July, and marched to Edinburgh, defeating a government army at the Battle of Prestonpans.

Charles then travelled south as far as Derbyshire, before returning to Scotland; his army was eventually crushed at the Battle of Culloden on the 16th of April 1746.

The portrait is thought to have been created at Holyrood in Edinburgh during Bonnie Prince Charlie’s short time in the city at the height of the Rising, by Ramsay (1713-1784).

Ramsay was born in Edinburgh, the son of a poet of the same name, and studied in London, Rome and Naples, before returning to Scotland in 1738.

A galleries statement says: "His portrait of Bonnie Prince Charlie is an accomplished early work, created when the sitter was 25 and the artist 32. Charles is depicted in half-length format, turning to confront the viewer directly.

"He wears a powdered wig, has a velvet robe fringed with ermine, and the blue riband and star of the Order of the Garter. The portrait was used as a prototype for painted and engraved versions, which were employed to promote the Jacobite cause."

Christopher Baker, director of the Scottish National Portrait Gallery, said: “This meticulous and dashing portrait is a work of great historical resonance, which in a real sense has now come home, as it will be celebrated as a key work in the nation’s Jacobite collection and as such become widely accessible.

"We are immensely grateful to everyone who has made its transference to public ownership, through the AIL scheme, possible.”

Edward Harley, the Acceptance in Lieu Panel Chairman, noted: "The Acceptance in Lieu Panel is pleased to have helped this iconic image of Bonnie Prince Charlie return to the city in which it was painted 270 years ago.

"It now takes its fitting place as one of the highlights of the great collection of the Scottish National Portrait Gallery where it can be enjoyed by all. This is indeed a unique moment in Scottish history."

The Acceptance in Lieu (AIL) scheme allows those who have an inheritance tax bill to gift significant items to the nation and "satisfy" more tax than by selling items on the open market.

It allows museums and galleries to increase their collections at no cost to them, while the donor gets the full market value.

"Executive devolution” arrangements are in place to enable Scottish ministers to deal with cases in which there is a "Scottish Interest."

AIL is administered across the UK by the Arts Council, which also oversees the Cultural Gifts Scheme.