How to infiltrate an embassy: first, try removing your MI5 name badge

The top secret operation was meant to be a great triumph in the war on terrorism, a cunning plan to extract vital intelligence. It ended in a shambles, with an embarrassing diplomatic incident between Britain and a key Commonwealth ally.

In the immediate aftermath of 11 September, while Tony Blair was publicly praising the role of Pervez Musharraf's regime in helping to combat Islamic terrorism, MI5 was busy infiltrating the Pakistani High Commission in London. Agents disguised as workmen removed documents, tracked staff and attempted to plant bugs.

The Pakistanis said yesterday that they would make an official complaint. A Foreign Office spokesman said: "The official comment is that we never comment on security matters. I am not going to be drawn on confidential diplomatic exchanges between the Pakistan government and the British Government." It is not surprising that the Pakistani legation, in Knightsbridge, south-west London, was a target. Western security services have long been convinced of links between Muslim fundamentalism and the Pakistani secret service, ISI.

Some of those involved in the assassination of the Northern Alliance leader Ahmed Shah Masood, in Afghanistan on 9 September 2001 allegedly received help with documents from agents of ISI.

The course of events appeared at times to be a version of Carry On Spying. MI5, it is claimed, failed to return calls left on its emergency hotline; did not discover that the agent it had recruited for the mission had a history of psychiatric problems; an officer arrived for a "secret" meeting in the street forgetting to remove her MI5 identification badge; another, who had already infiltrated the High Commission, risked the security of the operation by returning for a second attempt in another guise.

High Commission staff helpfully left codes for a cipher machine for sending secret messages on yellow Post-it notes stuck on a wall. Inside the offices of the military attachés, filing cabinets were left open with details of purchases of equipment.

The diplomats handed over confidential documents to a "workman" who promised to pulp them. He handed them over to MI5. At the centre of the mission was an MI5 agent codenamed Notation. He received tens of thousands of pounds for his work in the High Commission, with the instruction not to bank it so as to avoid the scrutiny of the Inland Revenue.

The paymasters appear to have been unaware that, years before, the agent had been sectioned under the Mental Health Act, and had spent a year in the Priory clinic. They also seem to have misjudged Notation's discretion - he described what had happened to journalists.

Notation's involvement began when a building contractor was invited to tender for renovation work on the dilapidated High Commission. He noticed a lack of security; rooms accessible without a security pass were stacked with documents marked "confidential". Visa applications were stacked in the basement. The contractor felt he should alert British security.

The contractor left messages on MI5's hotline but there was no response. It was easier to contact the CIA, through directory inquiries, at its offices in Langley, Virginia. A few days later he was contacted by a man calling himself Rick, to whom he handed plans of the legation at a meeting at the US embassy.

Later the contractor met a woman in her 30s calling herself Claire. "I work for the government", she said. The contractor was given his codename and instructions - to provide descriptions of layout, communications and security. When Notation provided them, Claire's reaction was that he was a "natural".

The next task was to take an MI5 agent, "Graham", into the High Commission. This too was successfully accomplished, and two men who worked at the building, of particular interest to MI5, were identified. The next coup was getting hold the documentation for "pulping".

But Notation was worried by what he saw as inefficiency and the fear that he would be abandoned if things went wrong. He wanted out.

A brief and terse meeting followed with Claire's boss, "a thin, balding man in his 50s" at a hotel in Victoria. Notation was tossed an envelope crammed with £50 bank notes and told not to contact Claire again. His life as a spy was over.