British Prime Minister Theresa May's Trade Bill, a vital part of her blueprint for Britain leaving the European Union (EU), scraped through the House of Commons Tuesday evening by just a small margin.
The government's Trade Bill passed its final hurdle in the Commons by 317 votes to 286.
May's win came minutes after an amendment that could have wrecked her Brexit plans was defeated by just six votes.
A group of pro-EU Conservative MPs supported a measure that would have changed the government's post-Brexit trade strategy.
If the new clause, put forward by Conservative MP Stephen Hammond, has succeeded, it would have meant the British government having to negotiate Britain's participation in a custom's union with the EU if it couldn't agree a free trade area deal with Brussels.
The government said being part of an EU customs union would prevent it from striking international trade deals, won the vote by 307 to 301, a slim majority for May of just 6.
Supporters of Hammond's new clause, which was backed by MPs from the main opposition Labor Party, were given hope of success when the government lost a vote on another aspect of its EU Trade Bill by just a handful of votes, 305 against 301 for the government.
That related to a bill about post-Brexit regulations of medicines and was only the second defeat in the Brexit legislative process for May since lawmakers started the process of passing laws to end Britain's membership of the EU.
Political correspondents in the Commons wrote that a number of Conservative rebels were seen to be herded into the offices of party managers and warned that if they backed Hammond's measure it would lead to a general election.
Hammond said in the Commons that with a heavy heart he was proceeding with his proposal for a new clause to the trade bill.
The Guardian newspaper described extraordinary scenes in the House of Commons with government trade minister George Hollingbery engaged in open negotiations with the customs union rebels, urging them to back down.
Labor MP, Chuka Umunna criticized four Brexit-supporting Labor MPs who voted in the final key vote. Had the four joined their Labor colleagues in the voting lobby, May would have faced a massive defeat.
Umunna said the four had helped May avoid a humiliating reverse over the customs union vote.
Labor's Brexit spokesman Keir Starmer said: "It was a very significant defeat for the government tonight on European medicines regulation amendment and a near miss on customs union amendment."
He said: "The margin is closing on these votes and we will keep at it."
Meanwhile plans by the government to close parliament on Thursday for its summer recess rather than next week were abandoned.
Speaker of the Commons John Bercow said parliament would now be in session next Monday and Tuesday.