Boris Johnson has said he will press on "undaunted" with his Brexit strategy despite losing a vital vote in the House of Commons.
He has vowed to introduce legislation needed to implement his agreement in Parliament next week.
But he will be compelled later to ask the EU for an extension beyond 31 October after MPs backed a motion designed to rule out a no-deal exit.
It was very close - the government lost by just 16 votes, by 322 by 306.
The motion, which was tabled by Independent MP Sir Oliver Letwin, "withholds approval" for Boris Johnson's Brexit deal until legislation implementing it has been passed.
It was due to be followed by a vote on the main government motion - whether or not to back the deal. The motion - amended because of the previous vote - was approved without MPs going into the division lobbies.
A vote on a cross-party amendment on preventing a no-deal referendum and holding a second referendum was also dropped.