British Prime Minister Theresa May has seen off a significant challenge to her Brexit plans, thwarting a rebel Tory move which could have forced her to try to keep Britain in a customs union with the EU.

However Mrs May went down to defeat 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.

In dramatic scenes in the House of Commons, ministers made a last-ditch effort to stave off defeat by offering to introduce amendments in the House of Lords which would deal with "the essence" of rebel Tories' concerns over future customs arrangements.

But despite their rejection of this overture, Mrs May emerged triumphant by a margin of just six votes, as the Commons rejected the key amendment by 307-301.

The 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 21 January next year.

Downing Street insisted that this would have breached Mrs May's red line, set out in last year's Lancaster House speech and enshrined in the Chequers Cabinet agreement, to take Britain out of the customs union.

Former minister Stephen Hammond, who joined five other Tory backbenchers in tabling the amendment, insisted its provisions were "entirely in line" with Mrs May's Brexit White Paper.

The crucial vote came moments after the government went down to defeat by 305-301 over medicines regulation.

Some 12 Conservatives - Mr Hammond, Heidi Allen, Kenneth Clarke, Jonathan Djanogly, Dominic Grieve, Phillip Lee, Jeremy Lefroy, Nicky Morgan, Bob Neill, Antoinette Sandbach, Anna Soubry and Sarah Wollaston - joined opposition MPs to vote the measure through.

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 EMA is being relocated from London to Amsterdam as a result of Brexit.

The votes were preceded by frantic activity in the Commons, with live negotiations conducted on the floor of the chamber as government whips led by Julian Smith made approaches to rebel MPs.

Meanwhile Mrs May has cancelled an attempt to end parliament early and give politicians an extended summer holiday, as members of parliament criticised the move as a ploy to ease pressure on her leadership.

The government had taken the unusual step yesterday of proposing to bring forward the closure of parliament for the summer to this Thursday, 19 July, from Tuesday 24 July.

But, with only 255 days until Britain leaves the EU, and Mrs May's Brexit plan in danger of being wrecked before she can even begin negotiating it with Brussels, politicians from all parties publicly signalled they would not back the move.

The government opted not to press ahead with the plan in parliament late today.