MPs have voted by a majority of one to force the prime minister to ask for an extension to the Brexit process, in a bid to avoid a no-deal scenario.
Labour’s Yvette Cooper led the move, which the Commons passed in one day.
The bill is due to be considered by the Lords later and will need its approval to become law, but it is the EU which decides whether to grant an extension.
It comes as talks between Conservative and Labour teams to end the Brexit deadlock continue.
Discussions between Prime Minister Theresa May and Labour leader Jeremy Corbyn on Wednesday were described as “constructive”, but were criticised by MPs in both parties.
Brexit Secretary Stephen Barclay told MPs he would hope the Lords would “scrutinise this bill passed in haste with its constitutional flaws”.
He added that there was “no guarantee” that the UK will not take part in the European elections in May and to participate would be a “betrayal” and “inflict untold damage”.
Meanwhile, Chancellor Philip Hammond has suggested that he expects Brussels to insist on a lengthy delay to Brexit. He also described a public vote to approve any final deal as “a perfectly credible proposition”.
But Health Secretary Matt Hancock told BBC Radio 4 Today he was “very strongly against” a public vote and he would not want to see a long extension to the Brexit process.
Ms Cooper’s attempts to prevent a no-deal departure from the EU passed by 313 votes to 312.
The draft legislation would force the prime minister to ask the EU for an extension to the Article 50 process beyond 12 April – and would give Parliament the power to decide the length of this delay to be requested.
Tory Brexiteers expressed frustration at the unusual process of a backbench bill clearing all stages in the Commons in a matter of hours, rather than months.
Mark Francois said: “It’s difficult to argue that you’ve had an extremely considered debate when you’ve rammed the bill through the House of Commons in barely four hours. That is not a considered debate, that is a constitutional outrage.”
The government’s attempt to limit the bill’s powers resulted in a 180-vote defeat – the second biggest defeat for a government in modern times.
Responding to the Commons vote, the government said the bill would place a “severe constraint” on its ability to negotiate an extension to the Brexit deadline before 12 April, the date the UK is due to exit.
‘Useful but inconclusive’
It comes as talks between government negotiators and Labour continue throughout Thursday after Mrs May and Mr Corbyn agreed a “programme of work”.
A No 10 spokesman said on Wednesday that both parties showed “flexibility” and “a commitment to bring the… uncertainty to a close”.
Mr Corbyn said the meeting was “useful, but inconclusive”, adding there had not been “as much change as [he] had expected” in the PM’s position.
The prime minister wants to agree a policy with the Labour leader for MPs to vote on before 10 April – when the EU will hold an emergency summit on Brexit.
But if they cannot reach a consensus, she has pledged to allow MPs to vote on a number of options, including the withdrawal agreement she has negotiated with the EU, which has already been rejected three times by MPs.
In either event, Mrs May said she would ask the EU for a further short extension to Brexit in the hope of getting an agreement passed by Parliament before 22 May, so that the UK does not have to take part in European elections.
The cross-party talks have provoked strong criticism from MPs in both parties, with two ministers resigning on Wednesday.
Chris Heaton-Harris quit on Wednesday afternoon, claiming his job at the Department for Exiting the European Union had become “irrelevant” if the government is not prepared to leave without a deal.
Wales Minister Nigel Adams also resigned, saying the government was at risk of failing to deliver “the Brexit people voted for”.
Reports in papers including the Sun suggest as many as 15 more – including several cabinet ministers – could follow if Mrs May strayed too far from previous commitments.
Among her “red lines” was leaving the EU’s customs union, which allows goods to move between member states without undergoing checks or being subject to tariffs. It also imposes the same tariffs on goods from outside countries.
Labour wants a new permanent customs union with the EU, while Northern Ireland’s Democratic Unionist Party – which has propped up Mrs May’s government – indicated on Wednesday that it could support the idea.
In an interview on ITV’s Peston programme, Mr Hammond said that – while the Conservative manifesto had pledged to leave the EU customs union – “some kind of customs arrangement” was always going to be part of the future structure.
Critics say remaining part of a European customs union would stop the UK negotiating its own trade agreements with the rest of the world.
Mr Corbyn is coming under pressure from senior colleagues in his party to make a further referendum a condition of signing up to any agreement.
Demanding the shadow cabinet hold a vote on the issue, shadow foreign secretary Emily Thornberry said not backing a confirmatory vote would be a “breach” of the policy agreed by party members at its last conference.
The party’s deputy leader, Tom Watson, told the Peston programme that Labour members would “find it unforgiveable” for “us to sign off on Theresa May’s deal without a concession that involves the people”.
However, party chairman Ian Lavery is reported to have warned against the idea, arguing that it could split the party.
European leaders will continue deciding how to respond to Brexit, with Ireland’s prime minister, Leo Varadkar, hosting German Chancellor Angela Merkel in Dublin later.
The UK has until 12 April to propose a plan to the EU – which must be accepted by the bloc – or it will leave without a deal on that date.
Are there any questions or issues that you want us to clarify?
Use this form to ask your question:
If you are reading this page on the BBC News app, you will need to visit the mobile version of the BBC website to submit your question on this topic.