An ancient pine forest which was used as a filming location in the film Harry Potter and the Deathly Hallows has been bought by a local community group.

Loch Arkaig pine forest near Spean Bridge in the Highlands has been sold by Forest Enterprise Scotland under the National Forest Land Scheme

The scheme gives community organisations first refusal to buy land where they will provide public benefit. The sale had to be concluded this winter or the forest could have been sold on the open market.

Read more: New play based on Alasdair Gray novel among project backed by £900,000 from Creative Scotland

Woodland Trust Scotland joined forces with Arkaig Community Forest, a group of local residents who had ambitious plans for the 2,500-acre site.

Gary Servant, of Arkaig Community Forest, said: "This is a great moment. The land has been bought and we have a fantastic opportunity to work together to restore these native woodlands and to reconnect local people with their forests. Everyone is very excited and we give heartfelt thanks to all who have supported us and have contributed to the appeal."

The Woodland Trust wants to restore the forest and stimulate sustainable economic activity around it. Pinewoods in the forest are said to have been degraded by historic felling, over-grazing and planting with non-native conifers which will be removed over the next 20 years.

Read more: New play based on Alasdair Gray novel among project backed by £900,000 from Creative Scotland

The forest will also be surveyed to identify "wildlife hotspots" which will be expanded through woodland management in the coming decades.

Carol Evans, director of Woodland Trust Scotland, said: "We are going to consult widely on our detailed plans for the wood. We want to see this special place established as a benchmark for the joint regeneration of both its native forest and local community."

An appeal was launched in April to raise £500,000 to fund the purchase and a further £4m was raised to restore the forest, which was used as a filming location for Harry Potter and the Deathly Hallows.

Simon Hodge, chief executive of Forest Enterprise Scotland, said: "This was one of the last applications to the National Forest Land Scheme.

"It has been great to see the way Arkaig Community Forest and Woodland Trust Scotland have worked in partnership to achieve their joint aims.

"I hope this success inspires other community organisations to consider how they might be able to develop similar projects under the new Community Asset Transfer scheme."

The appeal to make the purchase possible attracted funding from a range of benefactors and the largest contribution, £750,000, came from players of People's Postcode Lottery.

Read more: New play based on Alasdair Gray novel among project backed by £900,000 from Creative Scotland

The Loch Arkaig Appeal now stands at £2.9 million and has a final target of £4.5 million.

Ms Evans added: "Our long term goal of restoring this wood to its full glory will cost more than the purchase price. But today is a day for great celebration nevertheless. We are on our way."