MPs will vote on Thursday on delaying Brexit after they rejected the idea of leaving the EU without a deal.
In a night of high drama in the Commons, MPs surprised the government and voted by 312 to 308 to reject a no-deal Brexit under any circumstances.
The vote is not binding - under current law the UK could still leave without a deal on 29 March.
On Thursday, MPs will vote on whether to ask the EU for permission to delay the date for departure.
There could be a short extension - or a much longer one - depending on whether MPs backed the prime minister's existing withdrawal deal that has been agreed with the EU by 20 March, the government says.
That means Theresa May could make a third attempt to get her deal through Parliament in the next few days.
In a series of votes on no-deal Brexit, the Commons first voted by a margin of four to reject no deal outright.
Then, in another vote, they reinforced that decision by 321 to 278, a majority of 43.
That vote was on a motion which said the UK should not leave the EU without a deal specifically on 29 March, but with the option of a no-deal Brexit at any other time. It had originally been the government's motion.
The government wanted to keep control of the Brexit process, and keep no-deal on the table, so they ordered Conservative MPs to vote against it.
That tactic failed. Government ministers defied those orders and there were claims Theresa May had lost control of her party.
Thirteen government ministers - including Work and Pensions Secretary Amber Rudd, Business Secretary Greg Clark, Justice Secretary David Gauke and Scottish Secretary David Mundell - defied the government whips by abstaining in the vote.
Work and pensions minister Sarah Newton voted against the orders of the whips and has now resigned.
Mr Mundell said he backed the PM's deal and had always made clear his opposition to a no-deal Brexit.
In a crisis there can be opportunity.
This is now a crisis - the rules that traditionally have preserved governments are out of the window.
The prime minister has been defeated again. Her authority - if not all gone - is in shreds.
But for Number 10 there's an opportunity too, because MPs will soon be presented with a new choice - back the PM's deal, which has already been defeated twice, or accept the chance of a delay to Brexit.
This isn't the choice of a government that's in control. But the tactic is to make the best of chaos.
Speaking after the result of the vote was read out, Mrs May said: "The options before us are the same as they always have been.
"The legal default in EU and UK law is that the UK will leave without a deal unless something else is agreed. The onus is now on every one of us in this House to find out what that is."
1. MPs just voted clearly to say we should never leave EU without a deal— Laura Kuenssberg (@bbclaurak) March 13, 2019
2. Govt lost cos so many Tories, inc ministers, ignored what told to do by party bosses
3. May warns if MP s don't accept her deal v soon reality is that means a long delay to Brexit
4. Votes on delay tmrw
On Thursday, MPs will be asked if they want to delay Brexit until 30 June - to allow the necessary legislation to get through Parliament.
But that is only if MPs back Mrs May's deal by 20 March, the government says.
If they fail to back her deal by then, then the delay could be longer, Mrs May warned MPs, and it could clash with the European Parliament elections in May.
"I do not think that would be the right outcome. But the House needs to face up to the consequences of the decisions it has taken," she said.
MPs also voted by 374 to 164 to reject a plan to delay the UK's departure from the EU until 22 May 2019, so that there can be what its supporters call a "managed no-deal" Brexit.
This amendment was known as the Malthouse Compromise - after Kit Malthouse, the government minister who devised it.
Labour leader Jeremy Corbyn said that Parliament must now take control of the Brexit process and his party will work across the House of Commons to seek a compromise solution.
A European Commission spokesperson said: "There are only two ways to leave the EU: with or without a deal. The EU is prepared for both.
"To take no deal off the table, it is not enough to vote against no deal - you have to agree to a deal.
"We have agreed a deal with the prime minister and the EU is ready to sign it."