According to documents from the National Archives, Sir Ian Trethowan was put under pressure by Margaret Thatcher's Conservative government over the planned documentary.
In a letter flagged as "top secret and personal", the Tories even considered invoking their power to "veto" the BBC programme about MI5 and MI6 because it threatened to reveal details of the agencies' inner workings and question their accountability.
Cabinet secretary Robert Armstrong accepted that the power to veto the episode "would produce a tremendous hoo-ha, inside the BBC, the press and in parliament, about censorship".
But he added: "If we were convinced that the programme was likely to cause grave damage to the intelligence services, it might be right to risk the hoo-ha and use the power."
Sir Ian had told the press that no-one from the government had been shown the film, but the documents reveal that he did in fact hold meetings with the heads of MI5 and MI6.
The director general requested a video of the original 100-minute programme to be shown to Bernard Sheldon, the then legal adviser to MI5. Sheldon suggested a number of heavy cuts.
BBC News reports that Sir Ian then asked the BBC's head of news and current affairs to make many of the suggested cuts, reducing the programme by around half.
In a subsequent note to the prime minister, Armstrong said that "it looks as if Sir Ian Trethowan has not managed to clean the programme up to the extent we might have hoped".
Much more is known about MI5, MI6 and eavesdropping centre GCHQ in modern times, but in the 1980s the institutions were barely even acknowledged to exist.
Any suggestion that the BBC could expose the agencies was taken to the highest levels of Thatcher's cabinet, particularly over fears that the documentary could damage the effectiveness and morale of British intelligence.
The government decided to reject using its power to "veto" the edition from being broadcast, and most of the more controversial aspects of its contents ended up being leaked to the media anyway.
Also revealed in the released documents was that Number 10 Downing Street felt Sir Ian was a "weak" BBC director general, while the programme makers were concerned that he was pandering to the government's wishes.
Last month, it emerged that culture secretary Jeremy Hunt had attempted to stop the BBC from airing a controversial Panorama episode about alleged corruption within FIFA.
> More media news