David Cameron has definitively ruled out British involvement in any military action against Syria after the government lost a crucial vote in the House of Commons which was designed to help pave the way for a possible intervention.

In a devastating blow to his authority, the prime minister lost a government motion by 272 votes to 285 – an opposition majority of 13 – after dozens of Tory MPs joined forces with Labour. A tally of votes compiled by the Labour whips found that 30 Tory MPs rebelled. Ministers had thought they were secure after a Labour amendment was defeated, in the first vote of the night, by 332 votes to 220, a government majority of 112.

One MP shouted "resign" as the results were read out by the Speaker. Cameron said within minutes of the result that the government would respect the decision of parliament which means that Britain will not take part in military strikes against the regime of Bashar al-Assad.

Asked by Ed Miliband, the Labour leader, for an assurance that he would not use the royal prerogative to sanction British involvement in the proposed US-led military action, Cameron told MPs: "I can give that assurance. Let me say, the House has not voted for either motion tonight. I strongly believe in the need for a tough response to the use of chemical weapons, but I also believe in respecting the will of this House of Commons.

"It is very clear tonight that, while the House has not passed a motion, it is clear to me that the British parliament, reflecting the views of the British people, does not want to see British military action. I get that and the government will act accordingly."

Miliband said that British involvement in any military action was now "off the agenda". He added: "The prime minister has been cavalier and reckless. The result of the vote must be respected."

Michael Gove, the education secretary, was overheard shouting "disgrace" at Tory rebels, an MP told the Press Association.

The Scottish National Party's Westminster leader Angus Robertson told Sky News he watched as Gove had to be "persuaded to calm down" following the outburst. "Emotions were running high," Robertson said. Gove's wife Sarah Vine tweeted, in remarks that appeared to be aimed at Labour: "Pathetic losers who can't see past their own interests."

Sir Menzies Campbell, the former leader of the Liberal Democrats, highlighted the magnitude of the vote by saying that he could not remember a government defeat on a such a major foreign policy issue.

But Downing Street made clear that it would fight off any attempt to table a no confidence motion in the prime minister. One No 10 source said: "Our rebels are making clear that they support the prime minister on the economy and on his education and welfare reforms. They just did not support him on Syria."

There was deep irritation in the Cabinet that the prime minister had misjudged the mood of his parliamentary party and had single-handedly revived the fortunes of Miliband after a recent bad patch. But there was support for the view that Cameron faces no threat to his position.

Philip Hammond, the defence secretary who had accused Miliband before the vote of giving "succour" to the Assad regime by declining to support the government, said that the government defeat would strain the Anglo-American special relationship. Hammond told BBC Newsnight: "It is certainly going to place some strain on the special relationship. The Americans do understand the parliamentary process that we have to go through … Perhaps they have been surprised by the scale of opposition in parliament."

Some Tory cabinet ministers rounded on Nick Clegg, the deputy prime minister, who had struggled, in the closing minutes of the debate, to answer concerns on all sides of the House that the government motion would have taken Britain closer to joining a US military operation against the Assad regime in Syria after last week's chemical weapons attack.

Justine Greening, the international development secretary, and Mark Simmonds, the Foreign Office minister, missed the vote after claiming they could not hear the division bell. Downing Street was said to be unamused.

The government was defeated after the prime minister opened the debate by trying to make a virtue out of his U-turn on Wednesday when he conceded, under pressure from Miliband, that MPs would be given a second vote on any military action. He said the second vote would allow UN time and give parliament a major say on the crisis.

Cameron moved to build the case for action by releasing a three-page assessment of the Joint Intelligence Committee which said it was "highly likely" the Assad regime launched the chemical weapons attack. But the document failed to ascribe a motive to the regime for the attack.

Downing Street also released a government summary of the legal advice by the attorney general, Dominic Grieve, which said military action would be lawful "under the doctrine of humanitarian intervention". Opening the debate in a packed Commons, the prime minister said the attorney general had delivered a clear judgment. But he acknowledged that the intelligence agencies had not delivered a definitive verdict.

Philippe Sands, a leading expert in international law, said the document failed to provide a "sound or persuasive legal argument" in favour of military action.

Cameron pointed out that the JIC assessment concluded that the Assad regime had used the weapons on 14 occasions, warning of the dangers of failing to take action to deter future attacks. He told MPs: "I think we can be as certain as possible that a regime that has used chemical weapons on 14 occasions and is most likely responsible for this large-scale attack will conclude, if nothing is done, that it can use these weapons again and again on a larger scale and with impunity.

"People talk about escalation; to me, the biggest danger of escalation is if the world community – not just Britain, but America and others – stands back and does nothing. I think Assad will draw very clear conclusions from that."

Cameron's voice cracked with emotion as he spoke of the videos of victims after the attack. He said: "There are pictures of bodies with symptoms consistent with that of nerve agent exposure, including muscle spasms and foaming at the nose and mouth. I believe that anyone in this chamber who has not seen these videos should force themselves to watch them.

"One can never forget the sight of children's bodies stored in ice, and young men and women gasping for air and suffering the most agonising deaths – all inflicted by weapons that have been outlawed for nearly a century."

Miliband said the prime minister had failed to prove definitively that the Assad regime was responsible for the attack as he intensified the pressure on Cameron by pressing an alternative Labour amendment to a vote.

The Labour leader told MPs: "There will be some in this house who say that Britain should not contemplate action even when it is limited, because we do not know precisely the consequences that will follow.

"As I said, I am not with those who rule out action, and the horrific events unfolding in Syria ask us to consider all available options, but we owe it to the Syrian people, to our own country and to the future security of our world to scrutinise any plans on the basis of the consequences they will have."

However one senior Labour MP Jim Fitzpatrick resigned as a shadow minister before the vote, saying he was "opposed to military intervention in Syria, full stop".

Senior Tories criticised the government. David Davis, a former Tory leadership candidate and shadow home secretary said: "We must consider, being where we've been before in this House, that our intelligence as it stands might just be wrong because it was before and we have got to be very, very hard in testing it."

Cheryl Gillan, a former Wales secretary under Cameron, said: "I do not have enough accurate or verifiable information to support direct UK military action in Syria." Recalling the vote on Iraq, she said she was cautious because she "cannot sit in this House and be duped again".

But Bernard Jenkin, the chairman of the commons public administration committee, called on the House of Commons to stop "post-Iraq panic paralysing the country".

Earlier a row between the party leaderships broke out when Labour said Craig Oliver, Cameron's director of communications, had accused Miliband of giving succour to the Syrian regime by refusing to agree to a Commons vote on military action on Thursday.

Labour said the language used was "infantile".