Tony Blair's government tonight suffered its first ever defeat since coming to power, as MPs voted down proposals to allow police to hold terrorist suspects for 90 days without charge.

Despite last-minute appeals from the prime minister, and the return from overseas visits of both Gordon Brown and Jack Straw in order to vote, the government was defeated on the issue by 322 votes to 291, a larger than expected margin of 31.

A few minutes later, MPs voted for a rebel Labour amendment increasing the detention period to 28 days. That was passed by 323 votes to 290.

But the defeat on 90 days is a personal blow for Mr Blair, who strongly backed the police's demand for a three-month period.

According to parliament's division list, 49 Labour MPs rebelled against the government.

Mr Blair left the chamber shaking his head. He later told Sky News he would not be quitting and rejected accusations he was now "a lame duck".

He added: "People will believe parliament was deeply irresponsible."

The Conservative leader, Michael Howard, said the result left Mr Blair "seriously weakened" and called on him to "consider his position".

He added: "The prime minister has shown he no longer carries his party with him - and that is not good for the country."

Bookmakers William Hill shortened the odds on Mr Blair leaving office before the end of the year from 3-1 to 7-4 immediately after the vote.

MPs continued to vote on the remainder of the bill, which is less controversial. The bill may still face a stormy ride in the House of Lords, where there is no government majority.

Around the central lobby of Westminster, MPs were visibly digesting the shock of the government's first defeat.

Soon after the vote, the prime minister's official spokesman told reporters Mr Blair was "disappointed", but respected the will of parliament.

Asked whether the defeat reflected on Mr Blair's personal authority, the spokesman said: "This has been a one-off issue. It is an issue on which there has traditionally been a tension in parliament between those who, on the one hand, believe you have to do everything to protect the country's security, and, on the other hand, those who wish to protect civil liberties as they see it."

The shadow home secretary, David Davis, said: "I am delighted that we have shown Tony Blair that there are limits to what he can do."

"This is a victory for parliament and for Britain's freedoms."

The director of the civil liberties lobby group, Liberty, Shami Chakrabati, said she was "heartened" by the vote, but she warned it still doubled the existing permitted period for detention without charge. She also criticised the "overt political campaigning of senior police officers" for their part in lobbying MPs.

Earlier today, at prime minister's questions, Mr Blair told MPs to have a "sense of responsibility" and back the police's demand for a 90-day limit.

In heated exchanges between the prime minister and opposition leaders at question time, Mr Blair said it was his duty and "the duty of every member of this house" to support the police's request. In a 30-minute session dominated by the issue, one Tory backbencher shouted "police state" at Mr Blair.

Mr Howard said angrily: "We all want to fight terrorism effectively."

He argued that the government had failed to justify the need for 90-day detention and warned of riots, like those in France, if minority ethnic communities were alienated by the legislation.

Mr Blair reminded undecided Conservative MPs sitting behind Mr Howard that the "the police and those charged with fighting terrorism said the 90-day power was needed to make the country safe".

"You and your colleagues are going to have to make your decision today," he told Mr Howard.

"We have made ours. We believe this is right for our country. We believe it is necessary to protect our country from terrorism and I'm only sorry you don't agree."

With the government unsure of securing victory for the 90-day proposal later this afternoon, the cabinet ministers Mr Brown and Mr Straw were both ordered back from foreign visits by the chief whip to bolster the government's vote in the lobbies.

Labour loyalist Janet Anderson tabled a "fallback" amendment of 60 days, but Labour dissenter David Winnick also retabled his original proposal of 28 days - a period the Tories were prepared to accept.

Facing the possibility of the first defeat of his premiership, Mr Blair said he preferred to be right and lose than back down given the "compelling" case that the police had made to extend their powers of investigation.

"Sometimes it is better to lose and do the right thing than to win and do the wrong thing," he said.

Labour backbenchers made clear their concerns about the legislation a week ago, when the government's 66-seat majority was slashed to just one after 31 Labour MPs rebelled over another aspect of the bill. A rebel amendment to make an offence of "glorification" of terrorism carry "intent" was defeated.