Lawmakers blocked plans to detain terror suspects for 90 days without charge by 322 votes to 291, a majority of 31 against the government.
Wednesday's defeat in the House of Commons was scheduled to be followed by a later vote on whether the detention period should instead be 28 days or 60 days - options favoured by opposition parties and rebels in Blair's Labour Party.
The vote is humiliating for Blair, who put his authority on the line.
The prime minister took a major political gamble in refusing to back down on the plan, and called in every supporter to shore up numbers.
Treasury chief Gordon Brown was called back from an official visit to Israel, only two hours after arriving in the country.
Blair also ordered Foreign Secretary Jack Straw to cut short an official EU visit to Russia, while Labour Party chairman Ian McCartney, who is recuperating from heart surgery, volunteered to return to work for the vote.
The current maximum detention period for terror suspects without charge is 14 days and critics argued that extending it to 90 days would erode civil rights.
Grip on power
Brown was called back from an
official visit to Israel
The result raises serious question about Blair's grip on power. His popularity slumped due to the unpopular war in Iraq, and some Labour lawmakers now regard Blair as an electoral liability.
Blair has said he will not seek a fourth term in office, and although he could serve as prime minister until 2010, there is pressure on him to quit sooner.
Brown, a powerful and popular figure in the party, is said to covet the premiership and is reportedly impatient for Blair to hand over power.
The Terrorism Bill was drafted in the wake of the July attacks on London's transit system.
Designed to tackle Muslim extremism, it also aims to outlaw training in terrorist camps, encouraging acts of violence and glorifying terrorism.