A 300-year-old mansion in Midlothian has been “saved from collapse” after receiving a multi-million-pound restoration grant.

Campaigners have been fighting to save the Category A listed Mavisbank House near Loanhead since it was severely damaged by a fire 50 years ago.

Last week, the National Heritage Memorial Fund announced that a £5.3 million grant would be given to the Landmark Trust to restore the building and "save it from collapse".

Midlothian Council said they would be seeking to implement a compulsory purchase order to allow them to take over the site once the funding is in place.

READ MORE: MP declines Piers Morgan interview over Baby Reindeer character

The building has been derelict since it was gutted by a fire in 1973, with the ownership rights uncertain following the death of Mrs Willis Stevenson, who bought the property in the 1950s.

It was built by Scottish architect William Adam in 1723 as a summer residence for John Clerk of Penicuik – a well-known figure in the Scottish Enlightenment.

It was also used as a hospital for those living with mental illnesses during the 19th century before ultimately falling into disrepair.

In the 1980s Midlothian Council ordered for the building to be demolished.

However, volunteers maintained a vigil on the property until the decision was reversed.

The Landmark Trust, which restores and rents out historic buildings, said the restoration would take place in numerous phases.

The National: Neoclassical masterpiece Mavisbank 'one of Europe's most endangered'

They said: “The vital first phase will see the crumbling building and pavilions stabilised before any more historic fabric falls away, enable up-to-date condition surveys and resolve the long-standing ownership and access issues.

“A second phase is planned to involve the restoration of the house with extensive opportunities for people to learn traditional skills and follow the work in progress.

“The end use is expected to be a mixture of accommodation for short residential stays and public access, including regular free open days.

“The grant is the major enabler in a funding package which also includes £1.338m raised to date from various other sources, including the Landmark Trust’s own funds.”

Midlothian council leader Kelly Parry said: “We have long supported the opportunity to restore Mavisbank House, so this is wonderful news.

READ MORE: Rishi Sunak mentions 'Scottish nationalists' in speech about extremism

“Once the full funding package is in place, we will use our compulsory purchase powers to help secure a future for this important building.”

Dr Anna Keay, director of the Landmark Trust, added: “Mavisbank has hung by little more than a thread for so long, with demolition seriously contemplated on more than one occasion.

“The Landmark Trust is absolutely thrilled that through this grant from the National Heritage Memorial Fund, and the support and expertise of many others, we can start the process of saving it.”

The trust is seeking a further £1.6m to complete the project.