Labour was forced into an embarrassing U-turn on Monday over the government’s flagship immigration bill, after initially saying it would not oppose the legislation that brings free movement to an end.

The shadow home secretary, Diane Abbott, had sparked a backlash among MPs when she told the House of Commons that the frontbench would not vote against the post-Brexit legislation.

“The Labour party is clear that when Britain leaves the single market, freedom of movement ends, and we set this out in our 2017 manifesto. I am a slavish devotee of that magnificent document: so on that basis, the frontbench of the Labour party will not be opposing this bill this evening,” she said.

She added that Labour would abstain at this stage, known as second reading, and seek amendments later.

Abbott then tweeted that the bill put “the cart before the horse” because it seeks to establish a new immigration regime before the UK’s future relationship with the EU has been settled. “Labour wants to amend bill substantially. Today isn’t a final vote!” she added.

But 90 minutes later, amid a growing backlash on social media, Labour shifted its position and announced that it would whip its MPs to vote against the bill – though many had been told by the whips that they did not need to be present in Westminster on Monday.

Despite Labour’s change of heart, the government won the vote by 297 votes to 234, a comfortable majority of 63. With only a one-line whip in force, many of Labour’s 256 MPs had permission to be absent, and just 178 were present for the late-night vote.

The Liberal Democrat home affairs spokesman, Ed Davey, accused Labour of missing a potential opportunity to defeat the government, pointing out that two Conservative MPs, Anna Soubry and Ken Clarke, had rebelled.

“It is beyond belief that some Tory MPs were more organised on opposing the government’s hostile immigration policies than the Labour shadow cabinet,” he said.

One usually loyal backbench Labour MP described his party leadership’s flip-flop on the bill as a “meltdown”, adding: “Anyone with one foot on the ground could have told you the optics of the abstention, given Brexit sensitivities, was shocking.”

Several Labour backbenchers, including Chris Leslie and Angela Smith, had intervened to press Abbott, a longtime defender of immigration, on whether MPs would be whipped to oppose the bill – and signalled that they planned to rebel and vote against it.

Theresa May has repeatedly said that her Brexit deal will bring freedom of movement for EU citizens to an end, and that the immigration bill will establish the new, stricter regime.

Abbott had fiercely criticised the legislation as MPs debated it on Monday, calling it “one of the flimsiest pieces of legislation on a major issue that I or many of my colleagues have seen”. “This bill, the immigration white paper and the accompanying media narrative, plays to some of the very worst aspects of the Brexit debate. In the process, it risks doing irreparable damage to business, the economy and society,” she said.

Immigration is at the heart of Labour’s internal tussle over how to respond to the referendum result of June 2016. Some MPs, particularly in leave-voting constituencies, believe Labour has little choice but to accede to the demands of voters who want to see controls on immigration – a phrase Ed Miliband was criticised for plastering on mugs during the 2015 general election campaign.

Other Labour MPs, including the chair of the centrist group Progress, Alison McGovern, believe their party should be making the argument strongly for the benefits of immigration.

The Tory MP Ken Clarke said of Abbott: “She’s actually been making an extremely coherent root-and-branch criticism of the bill, and she has an excellent record on these things; but the problem is, we’re meant to be debating whether this House of Commons will approve the second reading of the bill.

“She’s denouncing it from beginning to end, but is saying the opposition don’t intend to vote against it. This makes the proceedings quite absurd.”