The city commuters streaming home through darkened streets last Tuesday night would never have recognised the middle-aged, bespectacled man slipping into the offices of a leading law firm.

Which is how Sir Richard Dearlove likes it, given that until last year he was running MI6. The message he was en route to deliver at that night's private seminar, before a discreet audience assembled by the law firm Ashursts, was a chilling one. There was 'extensive complacency' about the terrorist threat, he said, and those who thought July's London bombing was the worst Britain would suffer were wrong.

'We probably have to conclude that the clock is running on some much more dreadful events,' he said matter-of-factly. The dilemma now was how to stop them.

Quite, as Tony Blair might say. After a week which saw David Blunkett, his closest cabinet ally, forced out for the second time in a year and his majority cut to a humiliating one by a cross-party revolt over his terrorism bill, it is hard to tell which setback angers the Prime Minister most.

When Blunkett came under serious attack, Blair knew he must let go. On terrorism, however, the issue has had to be prised from his reluctant grip. One friend describes his mood as 'sheer exasperation', not just with the Tories - whom he regards as wantonly defying police warnings that they need new powers to tackle al-Qaeda - and of the public mood, but with his own party for aiding and abetting.

'Part of his fury is about the fact that we have suffered a self-inflicted wound, allowing the Conservatives to limp away, even though they are there for the taking on this issue,' says one friend. 'He thinks we could destroy Cameron and Davis on this.' Rebellious Labour MPs, meanwhile, accuse him of losing touch with reality in pursuit of yet more draconian crackdowns of unproven effectiveness.

The wrangle over plans to detain terrorist suspects for up to 90 days without trial has ended in what the ex-minister John Denham calls a 'blind game of poker' over who folds first. Were Labour MPs bluffing when they threatened their leader's first Commons defeat? Do the Tories dare bet against the risk of another bomb? And would Blair stake everything on a vote that, if he lost, could prompt demands for his resignation?

Charles Clarke, his Home Secretary, has been desperate for a deal: his chief whip, Hilary Armstrong, warned Blair that he would not carry Parliament. The Prime Minister's mood was, if anything, hardening. 'I don't think there is any sort of Plan B on 90 days,' said one government source bleakly.

Last-minute attempts to square that circle have left Clarke negotiating a climbdown, while Blair insists publicly that any compromise would be inadequate. The conclusion for many Labour MPs is that, weakened by weeks of infighting, he simply dare not risk a defeat that would leave him looking washed up. 'It's not about the terror bill: it's the symbolism of Tony losing his majority,' says another government source.

But it is not just political careers at stake. With the Association of Chief Police Officers (Acpo) adamant that without the new powers - on which MPs now vote this Wednesday - suicide bombers could go free, the dispute matters to every citizen in Britain.

Guy Fawkes mugs and gunpowder mustard sold briskly at the Commons gift shop last week. Once a traitor, now a tourist attraction, Fawkes neatly illustrates the dilemma for MPs: time blurs the lines between deadly treachery and legitimate protest.

Wednesday's revolt centred on plans to outlaw the glorification of terrorism - drawn up to prevent 'hate preachers' advocating jihad from mosques. But rebels say the measures are so vaguely drawn that they would - as Tory Dominic Grieve argues - outlaw 'the glorification of Robin Hood'.

Labour MPs fear it could become illegal to wear a T-shirt with an inflammatory slogan or say, as Cherie Blair once did, that she could understand why some Palestinians become suicide bombers. Librarians fear lending books on jihad could get them arrested: university professors say they risk prosecution for discussing al- Qaeda videos on politics courses.

Officially, the Home Office dismisses such scare stories, but Clarke is still planning concessions. The argument over 90 days, however, is more profound.

Acpo argues that building a case against sophisticated modern terrorists requires cracking computer codes, consulting police forces worldwide, retrieving forensic evidence from potentially contaminated sites - which cannot be reliably completed in the current allotted period of 14 days.

But those against the changes argue there is no evidence of people being freed because the police have run out of time. Since January 2004, there have been only 11 detentions for the full 13-14 days, in all of which the suspect was subsequently charged.

Neither can the malcontents be dismissed as diehard leftwingers or embittered ex-ministers. In cabinet, the attorney general, Lord Goldsmith, is among those privately unconvinced: in the Commons, prospective rebels range from impeccably on-message lawyer Emily Thornberry to the Muslim MP and Downing Street favourite Sadiq Khan, as well as the veteran loyalist David Winnick, author of rebel proposals for a maximum 28 days' detention.

The first sign of serious trouble came last Monday, when Sir Ian Blair, the Metropolitan Police chief, and the Met's head of counter-terrorism, Andy Hayman, were ushered into Downing Street. 'Tony didn't want to go into bat for 90 days without being absolutely certain they needed it,' says one source. 'But I've never seen them so adamant.'

Sir Ian promptly published a newspaper article warning it was the 'united view' of senior police that 90 days was necessary, while Hayman briefed journalists that it was not some kind of 'bartering tool' for negotiation. Both Blair and Armstrong, however, were busy with a second unfolding crisis around Blunkett.

The exit of Blunkett was a shattering blow not just for him, but for his boss. Blair overruled colleagues' warnings that it had been too soon to bring him back into Cabinet: now his friend was leaving under a cloud, putting Blair's own judgment on the line.

As Gordon Brown sat impassively beside Blair, Michael Howard used Prime Minister's Questions that morning to accuse Blair of being a lame duck, 'in office but not in power' - the words Norman Lamont used against John Major.

It was a breathtaking accusation from Howard, who, only months before was being attacked in similar terms by his own MPs. By the afternoon, the duck was pecking back, announcing that Blunkett would be replaced by the sharp but relatively unknown John Hutton.

It was a surprise to some: Hilary Benn, the International Development Secretary and son of Tony, is overdue for promotion and closer to the Chancellor, with whom difficult negotiations over pensions await. The choice of Hutton - a close friend and ex-flatmate of the Chancellor's bete noire Alan Milburn - spells defiance. Hutton, however, has ministerial experience of tussling with the rebels, over foundation hospitals. Right now, battle experience counts.

In other circumstances, Blunkett might have taken Wednesday afternoon off. But shortly after delivering his resignation statement, he was voting on the glorification clause - knowing Blair needed every vote he could get.

Brown spent most of the day in the Commons, badgering recalcitrant MPs to support the government: ministers were ordered back to Parliament to bolster the numbers. Nonetheless, Blair may only finally have averted defeat when the whips plucked a confused new MP from the rebel lobby into which he had accidentally strayed. The farce was complete.

Clarke had to play safe on the even trickier threatened vote over the 90-day clause. Promising 'urgent discussions' to reach a compromise, he persuaded Winnick not to push the Commons to a vote on a 28-day limit he would almost certainly have won. Disaster was averted, but not for long.

Next day, Blair told his Cabinet he still found the 90 days argument 'compelling' and that settling for an arbitrary figure would be pointless. 'The only logical argument is for 90 days: the rest is just parliament saying whatever it feels,' said one senior Whitehall source. By Thursday afternoon, Blair was publicly declaring that the police 'should have this power' if they wanted it. Was the deal off?

In asserting his own authority, however, Blair had badly undermined Clarke's, making it look as if he could not deliver on his word. The rebels were furious. 'We had people saying "We've been duped",' says another Whitehall source.

With Clarke demanding to be allowed to make a deal, a fudge was worked out whereby he would continue negotiating - and Blair would continue insisting publicly on 90 days, gambling on public opinion somehow bringing MPs around. Chief constables will brief them this weekend on why the new powers matter.

No wonder all leave for MPs on Wednesday has been cancelled - with one intriguing exception. While Blair faces his demons in the Commons, Gordon Brown will be meeting poverty-stricken Palestinians, a rather more popular mission on the backbenches.

Mischievous whispers that Blair is so disenchanted with Brown he would rather be succeeded by David Cameron will be firmly squashed when the Prime Minister addresses Labour MPs at a special meeting tomorrow. But anxiety about where he is leading them, not just on terrorism but on public service reform, persists.

'He's got to explain that he's not pursuing some egotistical legacy, that all the changes fit a set of Labour values,' says one ally.

Despite tearoom gossip about leadership challenges, there is no appetite for an immediate putsch. Quietly, however, MPs are discussing how to speed the transition of power from Blair to Brown, avoiding more messy revolts along last week's lines. Envious eyes are cast at the Tories' 1922 committee, party elders who are traditionally sent to dispatch an ailing leader.