The government has narrowly avoided a defeat on its Customs Bill after agreeing to Brexiteers' demands to change its wording.
MPs voted by 305 to 302 to support an amendment that critics said would undermine Theresa May's recently-announced negotiating position.
The government announced earlier it was backing the amendment, which was tabled by Brexiteer Tories.
Defence Minister Guto Bebb resigned so he could vote against the government.
The government's backing of the amendment sparked a backlash from pro-EU Tory MPs, who said the PM had "capitulated".
BBC political editor Laura Kuenssberg said the vote showed Theresa May had "very little capacity" to be flexible to either wing of her party.
MPs are also voting on a series of other amendments to the Customs Bill.
The one that has come closest to a government defeat prevents the UK from collecting taxes on behalf of the EU, unless the rest of the EU does the same for the UK.
Applying EU tariffs to products destined for the EU is part of Mrs May's plan to avoid friction at borders after Brexit.