Twelve Remain-supporting Tories defied the Prime Minister by backing the rebel amendment to her Brexit Trade Bill.
Cheers of relief resounded from ministers and Brexit-backing backbenchers when the result of the crunch division, 307 votes to 301, emerged.
Some had been braced for a nerve-racking vote of confidence in the Government tomorrow had the vote been lost.
A humuliating defeat would also have kickstarted a leadership contest with hardline Brexiteers waiting in the wings.
Theresa May thwarted a rebel amendment to her Brexit Trade Bill
I’m just sorry that it came to a vote – this is something the Government should have embraced.
But Mrs May suffered a setback when another rebel amendment, seeking to keep the UK in the European Medicines Agency, was passed by the Commons.
The Government was defeated by 305 votes to 301, a majority of four, in the division over the proposal tabled by pro-Brussels former Tory minister Philip Lee.
At the end of a tense series of votes tonight, the Trade Bill cleared the Commons when MPs backed giving the measure a third reading by 317 votes to 286, a majority of 31.
It will undergo further scrutiny in the Lords where it is likely peers could inflict further defeats on the Government.
International Trade Secretary Liam Fox told MPs the legislation would be “the confident first step that the UK takes towards establishing itself as an independent trading nation for the first time in over 40 years”.
Ministers are now braced for fresh attempts to amend the Bill by pro-Brussels peers in the House of Lords.
Pressure group Avaaz dubbed the Tory rebels ‘heroes’
Today’s votes marked the end of a tumultuous series of Commons debates over the Prime Minister’s Brexit plans.
She had faced threatened revolts by both Brexiteer and Remain-supporting Tories angry at her compromise plan for a future relationship with the EU.
Former minister Guto Bebb, who quit his defence brief on Monday in protest at Government concessions to hard Brexit Tories, was among 12 Conservative MPs who rebelled over the customs union plan.
He was joined by Heidi Allen, Kenneth Clarke, Jonathan Djanogly, Dominic Grieve, Stephen Hammond, Phillip Lee, Nicky Morgan, Bob Neill, Antoinette Sandbach, Anna Soubry and Sarah Wollaston.
Officials at the Department for International Trade tonight suggested the Government may try to overturn Dr Lee’s amendment in the House of Lords.
A Government spokesman said: “As set out in the White Paper, the UK is seeking participation in the European Medicines Agency.
“We would look to be an active participant and this would involve making an appropriate financial contribution.
1 of 15
“We will now reflect on this amendment and seek to revisit in the Lords.”
After his victory Dr Lee, who quit as a justice minister last month over the Government’s handling of Brexit, said: “I’m delighted that the House of Commons voted for my amendment to the Brexit Trade Bill.
“It’s now a negotiating objective for the Government our supply of medicines open after Brexit.
“I’m just sorry that it came to a vote – this is something the Government should have embraced.”
Opposition MPs and Tory rebels cheered as news of the Government defeat spread around the Commons chamber just before being officially announced by the tellers.
The setback for ministers led to speculation that a far more damaging defeat over the customs union proposal was looming.
Tory whips were said to have warned MPs that a motion of confidence in the Government would have to be tabled if the crunch vote was lost.
But cheers of relief resounded from the Government benches as the narrow victory became clear.
Amid frantic scenes in the run up to the vote, International Trade Minister George Hollingbery attempted to persuade Tory rebel Stephen Hammond to withdraw his amendment.
He promised that the Government would table a similar amendment to the Bill in the House of Lords with the phrase “customs union” removed.
Mr Hollingbery, after speaking to Chief Whip Julian Smith, interjected to say: “In recognition of contribution made by him and other members today it is my intention to bring forward an amendment in the other place that takes in the essence of new clause 18 but removes the defective elements relating to the Customs Union.
“The Government amendment will restate our intention to establish a customs arrangement with the European Union.”
Mr Hammond responded saying the offer was “generous”, but said: “Let’s do this the other way round, I’ll make you a generous offer. Why don’t you accept new clause 18 today and then amend it in the Lords.”
Tory former Cabinet minister Nicky Morgan, who co-tabled the pro-European amendment on the Customs Union along with Mr Hammond, said: “What we are proposing is eminently sensible.
1 of 14
“It is very clear that in this House there is a majority for a Customs Union to safeguard businesses and our constituents in future.”
She accused Tory Eurosceptics of trying to “scupper” the Prime Minister’s Brexit plans in Commons votes on the Government’s Custom Bill on Monday.
“Some of us tried to stop them, sadly we failed,” she said.
Following the vote, Labour’s shadow international trade secretary Barry Gardiner said: “The Government’s handling of Brexit over the past week has been an utter shambles. We have a Prime Minister who is in office, but not in power.
“Each day that Ministers waste arguing amongst themselves increases the risk of the UK crashing out of Europe without an agreement.
“Labour is clear that a new comprehensive customs union with the EU after Brexit is the best way to protect jobs, the economy and to avoid a hard border in Northern Ireland.
“Theresa May should finally accept that and get on with the job of negotiating for Britain.”