The financial mess that is the Cairngorm mountain railway could end up costing taxpayers £50 million to clean up, according to internal government documents obtained by the Sunday Herald.

The growing prospect that ministers will be asked to foot the bill for dismantling and removing the funicular from the mountain near Aviemore has been described as "scary" by Scottish government officials.

The documents also reveal how the company that ran the railway was on the verge of going bust before it was taken over by the government agency, Highlands and Islands Enterprise (HIE), in May - and how this fact was hidden from the public by HIE at the time.

When the railway was originally given planning consent in 1997, a legal condition was imposed obliging HIE to remove the entire facility and reinstate the land if the funicular was closed for more than two years.

Since then, as the mountain railway has tried to weather a series of worsening financial crises, the risk of closure has loomed ever larger. The prospect was confronted in private correspondence between HIE and the Scottish government in May this year.

HIE disclosed that it had estimated the cost of reinstatement at between £30m and £50m. This is higher than the £6m previously mentioned by the government's Forestry Commission, which had also investigated taking over the railway.

The estimate was high, HIE explained in a memo to government, because equipment might have to be carried out by helicopter in order to avoid damaging Cairngorm's sensitive habitat. Helicopters had to be brought in during construction causing "cost escalations".

In an email on May 1, one government official expressed concern about throwing "good money after bad" on the railway. "The prospect of a £30m bill for removal is pretty scary in financial and reputational terms," he said.

HIE has released more than 250 pages of memos and correspondence about its takeover of the railway earlier this year. The documents were requested by the Sunday Herald under freedom of information legislation.

For the first time they uncover the full story of how close the railway company, Cairngorm Mountain Limited (CML), came to bankruptcy. According to a confidential report to HIE from the accountants KPMG, the company was approaching a crisis last autumn.

CML had made "significant losses", KPMG reported. "Recent balance sheets showed CML was substantially insolvent, and that on an earnings basis, there was no prospect of that position changing."

Due to a drop in the number of visitors, the company made a loss of £167,000 in the year to April 30, 2007, and then a further £193,000 loss between May 1 and August 26, 2007. CML's liabilities at the end of April 2007 stood at £6.3m. Allowing the company to go into insolvency "would appear to present all parties with a scenario which would be problematic in terms of potentially damaging PR, and political problems", KPMG warned.

Despite a good skiing season last winter, the crisis at CML came to a head in spring, so an urgent HIE takeover was proposed. An emergency meeting of CML directors on May 8 was told the company's bank account had been "frozen". The minutes of the meeting recorded: "HIE believed that failure to agree in the short term could result in the company having to go into receivership. The company and HIE want to avoid this at all costs."

None of this was explained at the time. A draft HIE briefing advised officials to say "no" if asked by the media whether the HIE takeover was "to avert Cairngorm funicular railway going bust".

HIE argued last week that this was not misleading as there had been no risk of the railway itself going bust, as opposed to the company that ran it. But the government agency was still accused of "media manipulation" by Dave Morris, director of Ramblers' Association Scotland and opponent of the railway.

He said. "Government ministers must act to resolve this environmental and financial disaster at the heart of the Cairngorms National Park."

Roy Turnbull, vice-convener of the Badenoch and Strathspey Conservation Group, added: "Critics of the funicular consistently argued that it was likely to be an economic disaster, as it is proving."