John Major awarded himself “a full gloat” after seeing off challenges by William Rees-Mogg and parliamentary Eurosceptic rebels over the Maastricht treaty, confidential files from Downing Street reveal.

Gruelling political battles over the future of the EU are recorded along with the fact that before Black Wednesday, when the pound dropped out of the European Exchange Rate Mechanism, the Treasury sold about $30bn of foreign currencies in an attempt to defend sterling – some of it obtained through a secret deal.

Major’s attempts to ratify the Maastricht treaty, which created the constitutional basis for the union, involved protracted negotiations and internecine Conservative party feuding that lasted more than a year. He eventually faced down his critics by tabling a confidence motion in November 1993.

The events of 25 years ago demonstrate close parallels to Brexit, not least because the prime minister then was fiercely opposed by Lord Rees-Mogg, father of the Tory MP Jacob Rees-Mogg, who initiated legal action against the government in the hope of preventing the UK from signing the treaty.

The Maastricht bill finally passed through the Commons on 23 July 1993 and the courts dismissed Rees-Mogg’s judicial review challenge a week later. No 10 memos released to the National Archives in Kew on Tuesday show an embattled Major finally savouring his triumph.

A note from his private secretary, Rod Lyne, headed “Maastricht court action”, said: “Our lawyers are pleased with the judgment in the Rees-Mogg case. All three judges supported us on all three issues … The outcome was even better than our lawyers had expected.” On the letter, Major wrote: “Good. A full gloat is merited.”

Lyne also advised that: “The foreign secretary [Douglas Hurd] is exercising restraint in public comment … He does not wish to provoke the Rees-Mogg brigade into further quixotic action if there is a chance that they will now abandon their expensive and ultimately pointless [legal] action.”

Major’s parliamentary victory was celebrated by a host of foreign and EU commission leaders who sent private messages of congratulations. The Canadian prime minister, Kim Campbell, said he had demonstrated “unflinching leadership”.

Albert Reynolds, the Irish taoiseach, was the first to signal his approval. His fax was blurred in transmission and read by the N10 official initially as: “Now keep your head down and ? drink up”. A cleaner version arrived later, showing Reynolds’ message to be: “Now keep your head down and drive on.”

Major thanked him, replying: “You won’t know quite how good it feels finally to be through all the hoops, hurdles and heffalump traps of our 14-month obstacle course. It feels very good.”

In response to the Greek prime minister, Constantin Mitsotakis, Major wrote: “The outcome reflects the fundamental importance which Britain attaches to the community and to the work which we shall continue to do as a very active and committed member state.”

Rees-Mogg’s legal challenge had been resented by the prime minister’s office as a further complication but Sir Robin Butler, the cabinet secretary, wondered at one stage whether it made the tactics for the parliamentary vote easier since he could “go flat out to defeat the Labour amendment [on the social chapter]”.

He added: “There is a delicious irony in seeing Lord Rees-Mogg riding to the government’s rescue.”

Facebook Twitter Pinterest William Rees-Mogg, then editor of the Times, with Rupert Murdoch, the paper’s new owner, in 1981. Photograph: PA

During the passage of the bill, Major’s advisers made approaches to minority parties trying to win over their votes in support of the Maastricht bill. Against the DUP, one official wrote: “Really so hopeless? Nothing they’d be interested in?”

Major was sceptical that discussions with the Liberal Democrat leader, Paddy Ashdown, would produce anything. When the foreign secretary met him, no deal emerged. “The temptation to say ‘I told you so’,” Major noted on the memo.

After the Maastricht parliamentary vote, Major notoriously referred to Eurosceptic rebels in his cabinet as “bastards”, as the Tory civil war over Europe refused to die down.

Files from the previous year show that emergency intervention in the exchange markets before sterling dropped out of the ERM on Black Wednesday, 16 September 1992, was estimated by the Treasury in November that year to have involved sales of around $30bn of foreign currency reserves.

In 2005, Treasury documents obtained under the Freedom of Information Act revealed that the cost of the Black Wednesday debacle of 1992 may have been only £3.3bn, rather than the £13bn-£27bn previously estimated. That lower figure was based on a 1997 Treasury analysis.

