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 any no-deal scenario.
The bill, put forward by Labour’s Yvette Cooper, was passed by the Commons in just one day.
However, it will need to be approved by the Lords before it becomes law. It would also still be for the EU to decide whether to grant any extension.
The vote comes after Theresa May met Jeremy Corbyn for talks on Brexit.
The discussions between the leaders, who are trying to find agreement on a way forward, were described as “constructive”, but Mr Corbyn added that they were “inconclusive”.
Teams from both parties were meeting on Wednesday evening ahead of a full day of talks on Thursday to see if they can agree a Brexit plan to put to a vote in the House ahead of an emergency EU summit on 10 April.
If they cannot, the prime minister has pledged to put a number of options to the vote – including the deal she has negotiated with the EU, which has already been rejected by MPs.
Ms Cooper’s attempts to prevent a no-deal departure from the EU – which passed by 313 votes to 312 – had faced opposition from Tory Brexiteers.
They expressed frustration at the highly unusual process of a bill – the first stage of enacting a law – clearing all stages in the Commons in a matter of hours, rather than months.
One, Peter Bone, urged Speaker John Bercow to “make this farce stop” and prevent further votes.
However, the bill could undergo further scrutiny in the Lords as early as Thursday.
The bill was unusual as it is normally the government that decides which laws to put to the House.
But last week MPs voted to allow backbenchers to take control of business for the day, giving Ms Cooper the opportunity to have the bill debated and voted on.
As it stands, the UK has until 12 April to propose a plan to the EU – which must also be accepted by the bloc – or it will leave without a deal on that date.
Many MPs fear such a scenario would prove damaging to business and lead to chaos at ports.
Mrs May and Mr Corbyn agreed a “programme of work” on Wednesday, with a No 10 spokesman saying both parties showed “flexibility” and “a commitment to bring the… uncertainty to a close”.
However, the Labour leader said after the meeting there had not been “as much change as [he] had expected” in the PM’s position.
The cross-party talks have provoked strong reactions from MPs within both parties, with two ministers resigning on Wednesday.
One of them, Chris Heaton-Harris, claimed his job at the Department for Exiting the European Union was “irrelevant” if the government was not prepared to leave without a deal.
Chancellor Philip Hammond hinted that one reason Mrs May had approached Labour with a view to avoiding a no-deal scenario was that without a deal, “some form of direct rule [from Westminster]” in Northern Ireland would be needed to manage the border.
In an interview with ITV’s Peston programme, he also suggested the government might have to accept breaching one of the PM’s “red lines” by accepting Labour’s demands for a customs union with the EU.
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, he said.
Asked about a public vote to confirm approval of the final Brexit deal, Mr Hammond said: “Many people will disagree with it, I’m not sure there’s a majority in Parliament for it, but it’s a perfectly credible proposition and it deserves to be tested in Parliament.”
Mr Corbyn is coming under pressure from senior colleagues 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.