In a second parliamentary revolt in as many days, the House of Commons voted 327 to 299 in favour of a bill that could delay Brexit for three months.
It will now be scrutinised by the House of Lords, but peers have only a few days to pass the bill before Johnson suspends parliament next week.
The prime minister called for parliament to vote in favour of holding an early election on October 15, insisting Britain must leave the EU as planned on October 31, with or without a deal with Brussels.
He vowed he would "never allow" the delay, insisting the draft law would "surrender" control over Brexit negotiations to Brussels.
The government has already introduced a motion for a vote later Wednesday calling for a snap election to take place before an EU summit on October 17.
In yet another twist in the tortuous Brexit process, however, the opposition Labour party is expected to withhold its support for an election, which requires the backing of two-thirds of MPs, until the law receives final approval.
The defeat comes the day after MPs defied the government in a preparatory vote on the draft Brexit bill on Tuesday evening, including 21 of Johnson's own Conservative lawmakers -- several of them distinguished former ministers.
He expelled them all from the party, depriving his six-week-old government of a parliamentary majority.
However, Downing Street said Johnson would not be resigning whatever happens on Wednesday -- and US President Donald Trump offered him his support.
"Boris knows how to win. Don't worry about him. He's going to be OK," he told reporters in the White House.
- 'Sham' negotiations -
=======================
Johnson took office in July, three years after the 2016 referendum vote to leave the EU, promising to deliver Brexit whatever happens.
He says he wants to renegotiate the divorce deal his predecessor Theresa May agreed with Brussels, arguing that his threat of leaving with "no deal" will force EU leaders to agree better terms.
But the bloc has so far refused to reopen the text, and a senior EU source on Wednesday poured cold water on the idea that any last-minute deal could be struck at next month's Brussels summit.
The European Commission meanwhile said Britain had not yet come up with any alternative for the most controversial element of the current deal, the so-called "backstop" plan for the Irish border.
Labour leader Jeremy Corbyn said the negotiations Johnson talked about "are a sham -- all he's doing is running down the clock".
But Johnson insisted his team, which met with customs experts in Brussels on Wednesday, was making "substantial progress" in getting a deal.
The European Commission said the risk of a "no deal" exit has increased, a prospect many fear because of the economic damage likely to be caused by severing 46 years of UK-EU ties overnight.
However, Bank of England governor Mark Carney said Wednesday the institution believed the impact would be "less severe" than previously forecast, in part because of government preparations.
- Labour 'not dancing' -
========================
MPs voted on Tuesday to clear the Commons timetable on Wednesday to debate their own Brexit legislation, which they then rushed through in around five hours.
Their bill would force the government to delay Brexit until January 31 unless it has agreed an exit deal or secured MPs' approval for "no deal" by October 19.
But it also raises the prospect of rolling Brexit delays, and Johnson warned it would only cause "more confusion" and wreck any hopes of a deal.
To take effect, the bill must now be approved by the Lords, who were braced for a rare overnight sitting on Wednesday, with some bringing sleeping bags into the chamber.
Johnson earlier challenged Labour leader Corbyn to back his call for an election, to "let the people decide" how to resolve the Brexit impasse.
However, Labour is expected to abstain amid internal debate about whether to hold an election before or after Brexit.
"We're not going to be voting with Johnson today," Labour Brexit spokesman Keir Starmer said.
"We want a general election, but we're not dancing to his tune."