The government has suffered two shock defeats over attempts to overturn Lords changes to the controversial Racial and Religious Hatred Bill.
Demonstrations took place outside Parliament as the bill was debated
In a blow to Tony Blair's authority, MPs voted by 288 votes to 278 to back a key Lords amendment to the bill, which targets incitement to religious hatred.
The prime minister voted in the first division but not in the second, which was lost by one vote.
Home Secretary Charles Clarke told MPs the bill would now become law.
Mr Clarke claimed what had happened had been "a purely political act" by Tories, Lib Dems and members of his own side to defeat the government, rather than a genuine consideration of the issues in the bill.
The bill was aimed at extending the concept of the UK's race hate laws to cover belief but critics said ministers' proposals would have made it too wide-reaching.
'Victory for Parliament'
The government has only suffered one defeat since 1997 before Tuesday night's vote and that was on the Terrorism Bill in November.
Shadow attorney general Dominic Grieve said the defeats were "a victory for Parliament".
He branded the bill a "foolish manifesto commitment" introduced to "appease" some minority groups, and which had "threatened freedom of speech".
Mr Grieve said in multicultural Britain people had to accept that freedom of speech may mean people could be offensive to them, as well as vice versa.
He said: "This (bill) was completely contrary to our national tradition of free speech."
Evan Harris, the Liberal Democrats human rights spokesman, said: "The government just failed to understand that they can't take liberties with freedom of expression.
"This has showed tonight that we will stand up for freedom of expression."
Joke restrictions fear
Labour rebel Bob Marshall-Andrews said: "It was an awful misjudgement to believe you could get a bill like this through in the teeth of opposition from so many of your backbenchers."
Labour's John McDonnell, chair of the Socialist Campaign Group of MPs, said the vote showed that "democracy has broken out".
Shami Chakrabarti, of Liberty, said her organisation "takes great heart as Parliament stands up for our rights and freedoms once more".
Earlier in the Commons, Home Office Minister Paul Goggins told MPs that moves to combat religious hatred would not damage freedom of speech and only those who intending to "stir up hatred" would be caught by the government's plans.
But objectors, including comedian Rowan Atkinson, feared the proposals would limit artistic freedom and might have stopped comedians making jokes about religion.
The votes came after hundreds protested against the bill outside Parliament on Tuesday.
In the first vote, 26 Labour backbenchers rebelled and more than 40 others did not vote. At least 15 of these were Scottish MPs believed to have been campaigning for next week's Dunfermline and Fife West by-election.
DUP leader Ian Paisley was among the protesters
Analysis of the division list showed Mr Blair was recorded as voting with the government line in this division.
In the second vote, MPs voted by 283 votes to 282, majority one, to back the Lords - but Mr Blair was not recorded as having voted.
The Commons confrontation followed a series of defeats inflicted on the bill by peers in a bid to safeguard freedom of speech.
The peers said only "threatening words" should be banned by the bill, not those which are only abusive or insulting.
They also called for the offence to be intentional and specified that proselytising, discussion, criticism, insult, abuse and ridicule of religion, belief or religious practice would not be an offence.
Ministers had urged MPs to reject the Lords' amendments and back instead a government compromise instead.