The first step of a trade bill establishing the legal basis for Brexit has cleared the lower house of the British parliament with a vote of 317 in favour and 286 against.

The House of Commons gave the go-ahead on Tuesday to the government plan by closely defeating an amendment by several pro-European Union (EU) Conservative and Labour lawmakers.

The UK has not agreed on future bilateral relations with the EU including a “frictionless free trade area for goods”, Efe news reported.

After Tuesday’s vote, the trade bill, which shifts to UK law the existing European trade agreements, will go to the House of Lords that will study it after the summer recess.

READ | Donald Trump says Britain must get Brexit ‘carve out’ for US trade deal

Conservative International Trade Minister Liam Fox argued that the legislation would provide “stability and continuity” to companies until the UK could reach its own trade deals at the end of the 21-month transition period following Brexit, which will be enacted on March 29, 2019.

Fox called the trade plan “the confident first step that the UK takes towards establishing itself as an independent trading nation for the first time in over 40 years”, which can only happen when it leaves the European bloc.

British Prime Minister Theresa May narrowly survived a new rebellion in her government’s ranks — another crunch Brexit vote in Parliament — as she struggles to unify her divided party around her strategy for leaving the European Union.

READ | Brexit and the Indian perspective

The Conservative government defeated — by only 307 votes against to 301 in favour — an amendment introduced by its own backbench MPs to the future trade policy bill which would have kept Britain in a customs union with the EU if it failed to agree a free trade deal.

If the amendment had passed, it would have thrown May’s Brexit strategy into disarray and increased pressure on the already beleaguered leader. Government whips overcame the rebellion by a dozen Tory lawmakers — reportedly issuing last-ditch threats it would prompt a no-confidence vote in the prime minister — and scraped through by six votes.

It was bolstered by the support of four pro-Brexit opposition Labour Party MPs.

Ministers argued the amendment would put “massive restrictions” on its ability to forge “an independent trade policy” after Britain leaves the European Union next March.

READ | Theresa May’s Brexit plan could ‘kill’ US trade deal: Donald Trump

The government, however, lost another, less crucial vote on another backbench amendment calling for future participation in the European medicines regulatory network. The amendment was passed by 305 votes to 201, which forced May to maintain as an important goal the UK’s continued adherence to the European regulatory network for medicines.

The entire trade bill passed by 31 votes and now moves to the House of Lords for further scrutiny before returning to the Commons for a final vote.

May is battling to unite her Conservative Party around her Brexit blueprint formally unveiled last week following months of cabinet infighting.

It would see Britain ask the European Union for a free trade area for goods through a “facilitated customs arrangement” alongside a “common rulebook”.

Brexiteers believe that keeps Britain too close to the EU, while pro-Europeans think it fails to protect the country’s dominant services sector, among other gripes. The backlash has seen the prime minister face persistent rumours Tory MPs are planning to topple her.

Two top pro-Brexit ministers, Boris Johnson and David Davis, quit in protest last week, while a string of junior walkouts have followed suit, including two more officials on Monday.

Tuesday was also the second day running May faced revolt from backbench Tory lawmakers, after they failed on Monday by three votes to enact changes to a crucial post-Brexit customs bill.

The trade bill gives the government powers to adapt national legislation to comply with existing accords, establish new structures to fight any possible disputes following Brexit, and transpose into British law some 40 EU trade agreements, which the UK wishes to maintain until it can sign new treaties.

While the House of Commons debates these texts, the European Commission is analyzing the plan for future trade and customs relations it received from the UK government, the survival of which depends largely on the response from Brussels.