It is the Queen's speech that nobody ever wants to hear. In 1983 senior civil servants drafted a message they envisaged the monarch might have to deliver to the nation on the eve of all-out nuclear war with Russia.

The message, rousing and bleak in equal measure, was prepared during a secret Whitehall exercise designed to test Britain's reaction to international developments that tilted the world to the brink of a third world war. In it, the Queen would describe the "madness of war" and "the deadly power of abused technology" and call on Britain to summon the spirit of two world wars in its battle to survive.

The extraordinary speech forms part of a chilling 320-page war games scenario – codenamed Wintex-Cimex 83 – which was drawn up by top intelligence, defence and Home Office staff. It is revealed in a cache of secret documents released on Thursday by the National Archives, which evokes the shadow of nuclear armageddon that hung over Britain 30 years ago.

The address begins by recalling her last broadcast, when "the horrors of war could not have seemed more remote as my family and I shared our Christmas joy".

She continues: "Our brave country must again prepare itself to survive against great odds. I have never forgotten the sorrow and pride I felt as my sister and I huddled around the nursery wireless set listening to my father's inspiring words on that fateful day in 1939. Not for a single moment did I imagine that this solemn and awful duty would one day fall to me."

Prince Andrew, then a helicopter pilot with HMS Invincible, is, the Queen explains, already in action and "it is this close bond of family life that must be our greatest defence against the unknown".

Other files show the government rowed with the British Medical Association's over its estimate that Britain would suffer 33 million casualties in a nuclear attack, with more than 1 million dying from the blasts in London alone. A top-secret top secret briefing for whichever leader won the 1983 general election explained howthe Cobra room in Downing Street was equipped with facilities to trigger the launch of nuclear missiles, and advises the incoming prime minister that if a Soviet strike looms she or he should disperse ministers around the country to form "embryo governments" to take control if London is destroyed and the prime minister killed.

The briefing adds that the doctrine of "no first use of nuclear weapons" – one that was not accepted by Nato – was known as NOFUN.

The potential Queen's speech was written as in real life the UK ambassador to Moscow warned that the warlike rhetoric of Yuri Andropov, general secretary of the Soviet Communist party, had become "profoundly disturbing". Against this backdrop, the war planners produced a scenario in which a bellicose new USSR leadership had taken control and launched attacks on West Germany, Scandinavia, Italy and Turkey. Chemical and nuclear strikes would be next.

The scenario imagined half a million people heading for the hills of Wales and the West Country to escape bombings in which thousands had already died. Violent anti-war protests convulsed London and military bases in Scotland, while alcohol sales across the country rocketed and hospital medicine stores were looted.

Defence chiefs had concluded that Nato would have to launch a nuclear strike first or face defeat by the overwhelming force of the USSR, codenamed Orange. "The enemy is not the soldier with his rifle nor even the airman prowling the skies above our cities and towns but the deadly power of abused technology," the Queen continued in her address. "But whatever terrors lie in wait for us all the qualities that have helped to keep our freedom intact twice already during this sad century will once more be our strength."

She signs off: "As we strive together to fight off this new evil, let us pray for our country and men of goodwill wherever they may be. God bless you all."

As the imagined war unravels, the officials realise they may have made some serious strategic errors, not least in possessing large numbers of short-range nuclear weapons that, if used on the battlefield, would leave Nato worse off than the enemy. The scenario concludes with escalating chaos in the west and Nato taking the "solemn decision" to launch the first nuclear weapons against eastern bloc countries to "remind" Moscow that Nato will continue to resist.

There is panic, particularly in Scotland, where civilians expect a retaliatory nuclear strike, but the exercise ends on a bleakly hopeful note with Orange, its allies devastated by Nato nuclear attacks, offering to open peace negotiations. The Queen's address signs off: "As we strive together to fight off this new evil, let us pray for our country and men of goodwill wherever they may be. God bless you all."