THERESA May clung on for a little bit longer last night, after MPs narrowly backed the government over the Brexit Trade Bill.

All day it had looked certain that the Prime Minister was facing a big enough rebellion from her own MPs to see her defeated on an amendment which would have kept the UK in the Customs Union.

But the Tory whips were sent round to wavering backbenchers to tell them that they risked undermining May and that defeat would lead directly to the government tabling a confidence vote, risking a general election.

That seemed to be enough. The government won the vote 307 to 301.

Though 12 of her MPs rebelled, all the Scottish Tories voted with the government, so too did four Eurosceptic Labour MPs.

The Tories also seemed to break a promise with LibDem Jo Swinson.

The East Dunbartonshire MP is on maternity leave and was “paired” with Tory Brandon Lewis.

That means he’s not supposed to vote, but yesterday, he did.

“This is calculated, deliberate breaking of trust,” Swinson said, adding, “There’s a word for it – cheating.”

The amendment had been tabled by two former ministers, Nicky Morgan and Stephen Hammond, and would have obliged the Prime Minister to try and keep Britain in a customs union with the EU after Brexit.

Tory big beast Ken Clarke had backed the motion. He accused May and her government of trying to defeat it because they were “terrified of the Daily Mail, the Daily Telegraph and the [pro-leave] European Research Group”.

Opposition MPs had been hopeful, when, just moments before the vote, the government had been unexpectedly defeated on another amendment, over the EU’s regulatory system for medicines.

The Commons voted 304 to 301 for the government to try and secure continued UK participation in the EU regulatory network, the European Medicines Agency.

It means the Trade Bill, which passed 317 to 286, goes to the Lords heavily amended by both Remainers and Leavers.

But the lack of a customs union led to Angus MacNeil saying the Scottish Government now had “no option but to hold #indyref2 in next year or so”.

“Big bad clouds have golden linings,” he said, adding, “only applies to Scotland”.

The last few days have been unusual in parliament.

On Monday, the government, fearing defeat from staunch Brexiteers, accepted changes to the bill from the right-wing, pro-leave, European Research Group of Tory MPs.

Pro-EU Tories said those amendments wrecked the compromise plans agreed at Chequers, and unveiled in the Brexit White Paper published by the government just last week.

Tory remainer Heidi Allen told the BBC: “What was agreed at Chequers wasn’t perfect to us, wasn’t perfect to Leavers either, but the PM has worked exceptionally hard to find a decent first pitch to put the EU and to move forward from that.

“We were all set to drop all our amendments and back it and then suddenly we had these rather extreme last-minute manoeuvres from the ERG which seemed to us to deviate the Prime Minister from her plan and we weren’t prepared to let them do that – or at least try.”

Earlier in the day, Brexit Trade minister Liam Fox said it would have been impossible to “please everybody”.

“We have to have a compromise position that enables the country to get an agreement with the European Union.

“Here in Britain there is far too much negative, self-doubting pessimism in this process,” he told the BBC’s Today programme.

SNP Trade spokesperson Stewart Hosie said Westminster had once again voted against the interests of Scotland.

“The UK Government won this by the skin of her teeth and it was Labour’s hard Brexiteers who came to the aid of Theresa May – to their shame.

“The Tories utter arrogance has been staggering – and over an issue as important as this they have shown a total dereliction of duty. They have completely ignored Scotland’s interests and continue to ride roughshod over Scotland’s Parliament and people.”

However, Scottish Labour’s Shadow Secretary of State for Scotland Lesley Laird said it was the 13 Scottish Tory MPs who were to blame. She pointed to comments made after the general election in 2017 when Ruth Davidson suggested her MPs would push for a more “open” Brexit.

“This just further compounds what we already knew – that Ruth Davidson’s pledge that her MPs would stand up for Scotland was nothing short of a lie,” Laird said.

“At every step they have been nothing short of lobby fodder for Theresa May and Ruth Davidson has done absolutely nothing about it.

“The government have a majority of 13 and there are 13 Scottish Tories. The vote was lost by four. The fact that they have no backbone and are unwilling to do what’s in the best interests of the country tells you everything you need to know.”

An SNP amendment which aimed to ensure regulations could not be made without consent from devolved ministers, was defeated by 318 votes to 37 after Labour abstained.

As the votes were happening in the Commons, reports surfaced suggesting the EU was preparing to issue emergency guidelines to member states today telling them to immediately step up preparations for a no deal Brexit.

First Minister Nicola Sturgeon said it was “hard to confidently disagree” that Britain might now be heading for a hard Brexit. She tweeted that Monday and Tuesday had seen May’s “total capitulation to the hard Brexiteers, who actually want no-deal outcome, and defeat of a sensible, compromise customs union amendment”.