The fate of an obscure but special private country home in Ayrshire, the "sleeping beauty", first came to the attention of the Prince of Wales two and a half years ago.

But it wasn't until two minutes past midnight yesterday that a deal to save the 200-year-old house, near Cumnock in Ayrshire, was finalised.

In the early hours, a consortium of trusts, led by Prince Charles, the Duke of Rothesay, finalised a £45m deal and were informed officially of their success by the solicitors of Johnny Dumfries, the Marquis of Bute.

A total of £20m has been guaranteed by The Prince's Charities Foundation, with a further £25m put together by a plethora of trusts and heritage bodies: The Monument Trust provided £9m, The National Heritage Memorial Fund £7m, the Scottish Executive gave £5m, The Art Fund £2.25m, The Garfield Weston Foundation £1m, Sir Siegmund Warburg's Voluntary Settlement gave a further £250,000 and the Dunard Fund gave $250,000, (£125,000).

The deal, driven predominantly by the prince, includes the crucial purchase of 66 acres of land in the Cumnock area near the estate: this will now be developed into an "ideal village", which may resemble the Prince of Wales's Poundbury village in Dorset. The sale of its houses will go some way to recouping his costs.

An independent trust, The Great Steward's Dumfries House Trust, is being established to organise the presentation and maintenance of the house, which will now open to the public next year.

The deal is unprecedented for the Prince of Wales: he has never backed the purchase of a building of this scale and expense before.

Mark Leishman, his deputy private secretary, said the prince first became interested in the building and its surroundings, which include 2000 acres of land, when the marquis, the former racing driver known as Johnny Bute, failed to come to a deal with the National Trust in 2005.

"You have to look back to that event two and half years ago," he said, "and, since then, the prince was very aware of the continuing story. And it became pretty clear in the last three weeks that time was running out.

"The prince was pretty concerned with the way the house and its contents could be divided up by private sale.

"There were two reasons driving his involvement: the first was the historical importance of the house and its contents, of course, but secondly he sees the house and estate as having enormous potential as an engine of economic regeneration.

"It is fair to say he has never been involved in the purchase of a property on this scale before, it is unique in that sense."

For months, campaigners had feared the house, built by the Adam brothers in the 18th century, and its contents, including £12m worth of unique furniture created by Thomas Chippendale, would be split up.

More than a dozen private individuals - from the UK, Ireland and overseas - bid "significant sums" for the house, and the successful bidder was due to be announced tomorrow. The Christie's sale of its contents was still planned to go ahead in July.

But yesterday, as the consortium of trusts secured the deal, there was delight, and relief, from all bodies involved or affected by the fate of Dumfries House.

In a statement, Mr Dumfries, 49, said: "I am delighted to say that, following the closing date, I have decided to sell Dumfries House and its contents to the nation.

"Dumfries House and its contents will remain intact as a unique example of Georgian craftsmanship. Since announcing my intention to sell Dumfries House in 2004, considerable effort has been made by all parties involved to reach this conclusion. The amount of time, effort and commitment put into this rescue package by Marcus Binney of Save and his colleagues and The Art Fund has been rewarded with an appropriate outcome however, there is no doubt the person responsible for galvanising the heritage funding bodies and who also generated separate finance is Prince Charles.

"In my opinion, the rescue package would have failed without his intervention."

The fate of the house has generated much correspondence in The Herald, and David Price, one of the local campaigners to save the house for the nation, said last night: "I am thrilled. And sense has prevailed at last. The investment by the Prince of Wales is an incredible step. Now what was a not very well-known place will be open to the public. It's our own sleeping beauty and it has been saved."

Original estimates put a price of around £20m on both the house and its contents and the £45m total covers the purchase of the house, the land and its contents as well as the creation of the trust to run the house as a public attraction.

Marcus Binney, president of Save Britain's Heritage, which led the campaign for many months, said: "Dumfries House has been saved against the toughest of deadlines by the decisive intervention of the Prince of Wales.

"The dispersal of one of the finest collections of great furniture in the United Kingdom has been averted at the last moment, ensuring a wonderfully intact Adam house, which very few people have ever seen, will now be open for all to enjoy."

Alex Salmond, First Minister, said he was delighted at the outcome of the bid, and hoped the project could boost tourism in that part of Scotland.

He said: "When His Royal Highness told me of his plans, I was determined to do what we could to help.

"The house and its exquisite furniture collection are internationally acclaimed - a world-class product of the Scottish Enlightenment. I want them to become a showcase for a newly confident Scotland."

Through the keyhole

  • Dumfries House was built between 1754 and 1759 for William Crichton-Dalrymple, Earl of Dumfries and Stair.
  • It was designed by the Adam brothers, John, Robert and James.
  • It contains one of the most important collection of Rococo furniture by Thomas Chippendale to remain in private - and now public - hands.
  • As well as its unique Chippendale furniture made especially for the house, it is also home to items made by renowned Scots furniture makers William Mathie, Alexander Peter and Francis Brodie.
  • The last member of the Bute family to live in the house was Eileen, Dowager Marchioness of Bute, who died in 1993.
  • Its many treasures include a gilt, rosewood, padouk and sabicu Chippendale bookcase which was expected to be sold for between £2m and £4m.
  • Also highly priced were George II giltwood pier glasses, from 1759, by Chippendale worth up to £1m.