Theresa May has narrowly defeated a rebel Tory move which could have forced her to keep Britain in a customs union with the EU.

The Prime Minister was saved from a humiliating reverse after MPs backed the government by a margin of just six votes, rejecting the amendment by 307-301.

Labour Brexiteers Frank Field, Kate Hoey, John Mann and Graham Stringer – along with independent Kelvin Hopkins – voted with the Government.

But 12 Conservatives – Guto Bebb, Heidi Allen, Kenneth Clarke, Jonathan Djanogly, Dominic Grieve, Stephen Hammond, Phillip Lee, Nicky Morgan, Bob Neill, Antoinette Sandbach, Anna Soubry and Sarah Wollaston – broke ranks to back the customs union measure.

 May was defeated on a separate amendment to her flagship Trade Bill, which will require her to seek continued UK participation in the EU’s system for regulation of medicines after Brexit by 305 votes to 301.

A senior minister said it was ‘extraordinary that we lost the vote that didn’t matter and won the one that did’.

But added: ‘I don’t know where we go from here.’

The unsucessful amendment would have forced the Government to adopt a negotiating objective of seeking to keep the UK in ‘a customs union’ with the EU after Brexit, unless it has managed to negotiate a ‘frictionless free trade area for goods’ by January 21 next year.

Downing Street insisted this would have breached  May’s red line to take Britain out of the customs union.

But former transport minister Mr Hammond insisted its provisions were ‘entirely in line’ with Mrs May’s Brexit White Paper.

The successful amendment requires Mrs May to make it an objective in negotiations with Brussels to ensure that the UK can continue to participate in the regulatory network operated by the European Medicines Agency.

The Trade Bill later passed its third reading by a margin of 317 to 286 and will go on to the House of Lords.

International Trade Secretary Liam Fox said 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’.

But his Labour shadow 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.’

Pro-EU Labour MP Chuka Umunna hit out at Labour Brexiteers who opposed the customs union amendment, saying: ‘It’s very disappointing and our communities will question why Labour MPs are jeopardising jobs.’

Green Party co-leader Caroline Lucas, a leading supporter of the People’s Vote campaign for a second referendum, said Brexit had ‘sunk further into the Westminster quagmire’.

And Liberal Democrat Brexit spokesman Tom Brake said Mrs May’s Chequers negotiating strategy was now ‘in tatters’.

‘The passing of this deeply flawed bill can’t mask the profound splits at the heart of the Tory party,’ said Mr Brake.

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. We will now reflect on this amendment and seek to revisit in the Lords.’