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.
Labour's Yvette Cooper led the move, which the Commons passed in one day.
The bill will need Lords approval to become law, while it is the EU who decides whether to grant an extension.
It comes as talks between Prime Minister Theresa May and Labour leader Jeremy Corbyn to end the Brexit deadlock are set to continue.
Discussions between the two leaders on Wednesday were described as "constructive", but were criticised by MPs in both parties.
Meanwhile, Chancellor Philip Hammond has suggested that he expects Brussels to insist on a lengthy delay to Brexit and described a public vote to approve any final deal as "a perfectly credible proposition".
Ms Cooper's attempts to prevent a no-deal departure from the EU passed by 313 votes to 312.
The draft legislation by the former Labour minister 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.
Tory Brexiteers expressed frustration at the unusual process of a backbench bill - the first stage of enacting a law - 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.
The draft legislation will next be considered in the Lords as early as Thursday.