Previously secret government files reveal how officials helped former prime minister Margaret Thatcher carefully manage negotiations with the Saudis to land the UK's biggest ever arms deal.

In April 1985 Mrs Thatcher visited Saudi Arabia on her way back from a tour of south-east Asia, a stopover that helped clinch the notorious Al-Yamamah contract.

The Saudis had been leaning towards buying fighter aircraft from the French, but Mrs Thatcher lobbied hard on behalf of British industry and undertook a series of negotiations with the Saudi royal family to press the deal home.

The Al-Yamamah deal proved highly controversial, mired in dispute from the moment it was signed by Saudi defence minister Prince Sultan and then defence secretary Michael Heseltine in 1985.

Anti-arms trade campaigners were appalled that Britain was supplying military hardware to a regime with a reputation for human rights abuses and torture, and allegations emerged that the contract had been won through bribery payments.

The £43 billion contract saw defence giant BAE Systems supply more than 100 fighter jets to Saudi Arabia, but there were claims the firm ran a multimillion-pound "slush fund" offering sweeteners to Saudi royals and shady intermediaries in return for lucrative contracts.

A 1992 report by the National Audit Office into the deal was suppressed over fears it may offend the Saudis - an unprecedented step - and more than a decade later the Serious Fraud Office launched an investigation.

That was dropped in 2006 after intervention by Tony Blair, and in 2010 BAE Systems eventually reached a settlement over corruption claims with the Serious Fraud Office and the US Department of Justice that cost it £286 million.

Files released by the National Archives at Kew in west London reveal the delicate tightrope the prime minister had to walk to initially secure the contract - and the efforts to keep the talks secret.

Mrs Thatcher was invited by Prince Bandar to meet King Fahd in Riyadh, a trip supported by Mr Heseltine on the proviso there was certainty it could clinch a deal to sell Tornado planes to the Saudis.

Sounding out the invitation behind closed doors, Mr Heseltine's private secretary, Richard Mottram, wrote to Mrs Thatcher's foreign policy adviser, Charles Powell: "It seems unlikely that Prince Bandar would seek to engineer such a meeting unless something positive was likely to come out of it: otherwise he runs the obvious risk of embarrassing both the prime minister and King Fahd."

A briefing document from the Foreign Office to Downing Street suggested the prospects of a deal over the Tornados was likely to be the true intention of the visit, but a full confirmation was needed.

It said: "To date, we only have Prince Bandar's word for it that the king has decided to buy Tornado. We need to get this made more precise and more explicit.

"Tackling the King in person is probably the only way of smoking the Saudis out."

The government tried to keep discussions secret from the press, with a briefing that the prime minister would "take opportunities as they arise to promote major export projects" if officials were pressed for information on a Tornado deal.

But, behind the scenes, detailed arguments to secure the contract were being planned.

A confidential document on the meeting outlined "tactical arguments" to secure an "early and favourable decision to purchase Tornado IDS and Hawk training aircraft", including the Tornado's favourable price against the F15, its superiority in an offensive/tactical support role and a gentle threat that prices could not be held indefinitely.

The meeting was officially touted as a discussion of political developments in the Middle East, but it was accepted that with 20 journalists invited on the trip it was likely the visit would be mainly presented as being about the Tornado deal.

Another briefing note urged caution over how Mrs Thatcher would bring up discussions.

It said: "I have no doubt that the prime minister will wish to discover the position on Tornado when she sees the king, but I feel bound to advise that she should aim to give the king himself the opportunity to raise the matter first, and that it would not be in our interests to appear to pressure the Saudis unduly at this point."

An official record of the meeting between Mrs Thatcher and King Fahd on April 14 1985 made no mention of discussions over Tornados or an arms deal.

But in a letter to the king the following day, the prime minister mysteriously wrote: "I was glad that we were able to discuss a further matter privately over lunch.

"I look forward to receiving your majesty's personal envoy soon, in order that we may conclude this matter successfully."

That September an agreement in principle was signed for the UK to supply Tornado, Hawk and PC9 aircraft to Saudi Arabia.

There were also claims that Mrs Thatcher's son, Mark, made millions of pounds from the arms contract.

Mr Thatcher was accused of receiving £12 million in commission for acting as a go-between in the deal, but ministers repeatedly cleared him of any involvement.