She had probably done this a dozen times before. Modern digital technology had made clandestine communications with overseas agents seem routine. Back in the cold war, contacting a secret agent in Moscow or Beijing was a dangerous, labour-intensive process that could take days or even weeks. But by 2004, it was possible to send high-speed, encrypted messages directly and instantaneously from CIA headquarters to agents in the field who were equipped with small, covert personal communications devices. So the officer at CIA headquarters assigned to handle communications with the agency's spies in Iran probably didn't think twice when she began her latest download. With a few simple commands, she sent a secret data flow to one of the Iranian agents in the CIA's spy network. Just as she had done so many times before.

But this time, the ease and speed of the technology betrayed her. The CIA officer had made a disastrous mistake. She had sent information to one Iranian agent that exposed an entire spy network; the data could be used to identify virtually every spy the CIA had inside Iran.

Mistake piled on mistake. As the CIA later learned, the Iranian who received the download was a double agent. The agent quickly turned the data over to Iranian security officials, and it enabled them to "roll up" the CIA's network throughout Iran. CIA sources say that several of the Iranian agents were arrested and jailed, while the fates of some of the others is still unknown.

This espionage disaster, of course, was not reported. It left the CIA virtually blind in Iran, unable to provide any significant intelligence on one of the most critical issues facing the US - whether Tehran was about to go nuclear.

In fact, just as President Bush and his aides were making the case in 2004 and 2005 that Iran was moving rapidly to develop nuclear weapons, the American intelligence community found itself unable to provide the evidence to back up the administration's public arguments. On the heels of the CIA's failure to provide accurate pre-war intelligence on Iraq's alleged weapons of mass destruction, the agency was once again clueless in the Middle East. In the spring of 2005, in the wake of the CIA's Iranian disaster, Porter Goss, its new director, told President Bush in a White House briefing that the CIA really didn't know how close Iran was to becoming a nuclear power.

But it's worse than that. Deep in the bowels of the CIA, someone must be nervously, but very privately, wondering: "Whatever happened to those nuclear blueprints we gave to the Iranians?"

The story dates back to the Clinton administration and February 2000, when one frightened Russian scientist walked Vienna's winter streets. The Russian had good reason to be afraid. He was walking around Vienna with blueprints for a nuclear bomb.

To be precise, he was carrying technical designs for a TBA 480 high-voltage block, otherwise known as a "firing set", for a Russian-designed nuclear weapon. He held in his hands the knowledge needed to create a perfect implosion that could trigger a nuclear chain reaction inside a small spherical core. It was one of the greatest engineering secrets in the world, providing the solution to one of a handful of problems that separated nuclear powers such as the United States and Russia from rogue countries such as Iran that were desperate to join the nuclear club but had so far fallen short.

The Russian, who had defected to the US years earlier, still couldn't believe the orders he had received from CIA headquarters. The CIA had given him the nuclear blueprints and then sent him to Vienna to sell them - or simply give them - to the Iranian representatives to the International Atomic Energy Agency (IAEA). With the Russian doing its bidding, the CIA appeared to be about to help Iran leapfrog one of the last remaining engineering hurdles blocking its path to a nuclear weapon. The dangerous irony was not lost on the Russian - the IAEA was an international organisation created to restrict the spread of nuclear technology.

The Russian was a nuclear engineer in the pay of the CIA, which had arranged for him to become an American citizen and funded him to the tune of $5,000 a month. It seemed like easy money, with few strings attached.

Until now. The CIA was placing him on the front line of a plan that seemed to be completely at odds with the interests of the US, and it had taken a lot of persuading by his CIA case officer to convince him to go through with what appeared to be a rogue operation.

The case officer worked hard to convince him - even though he had doubts about the plan as well. As he was sweet-talking the Russian into flying to Vienna, the case officer wondered whether he was involved in an illegal covert action. Should he expect to be hauled before a congressional committee and grilled because he was the officer who helped give nuclear blueprints to Iran? The code name for this operation was Merlin; to the officer, that seemed like a wry tip-off that nothing about this programme was what it appeared to be. He did his best to hide his concerns from his Russian agent.

The Russian's assignment from the CIA was to pose as an unemployed and greedy scientist who was willing to sell his soul - and the secrets of the atomic bomb - to the highest bidder. By hook or by crook, the CIA told him, he was to get the nuclear blueprints to the Iranians. They would quickly recognise their value and rush them back to their superiors in Tehran.

The plan had been laid out for the defector during a CIA-financed trip to San Francisco, where he had meetings with CIA officers and nuclear experts mixed in with leisurely wine-tasting trips to Sonoma County. In a luxurious San Francisco hotel room, a senior CIA official involved in the operation talked the Russian through the details of the plan. He brought in experts from one of the national laboratories to go over the blueprints that he was supposed to give the Iranians.

The senior CIA officer could see that the Russian was nervous, and so he tried to downplay the significance of what they were asking him to do. He said the CIA was mounting the operation simply to find out where the Iranians were with their nuclear programme. This was just an intelligence-gathering effort, the CIA officer said, not an illegal attempt to give Iran the bomb. He suggested that the Iranians already had the technology he was going to hand over to them. It was all a game. Nothing too serious.

On paper, Merlin was supposed to stunt the development of Tehran's nuclear programme by sending Iran's weapons experts down the wrong technical path. The CIA believed that once the Iranians had the blueprints and studied them, they would believe the designs were usable and so would start to build an atom bomb based on the flawed designs. But Tehran would get a big surprise when its scientists tried to explode their new bomb. Instead of a mushroom cloud, the Iranian scientists would witness a disappointing fizzle. The Iranian nuclear programme would suffer a humiliating setback, and Tehran's goal of becoming a nuclear power would have been delayed by several years. In the meantime, the CIA, by watching Iran's reaction to the blueprints, would have gained a wealth of information about the status of Iran's weapons programme, which has been shrouded in secrecy.

The Russian studied the blueprints the CIA had given him. Within minutes of being handed the designs, he had identified a flaw. "This isn't right," he told the CIA officers gathered around the hotel room. "There is something wrong." His comments prompted stony looks, but no straight answers from the CIA men. No one in the meeting seemed surprised by the Russian's assertion that the blueprints didn't look quite right, but no one wanted to enlighten him further on the matter, either.

In fact, the CIA case officer who was the Russian's personal handler had been stunned by his statement. During a break, he took the senior CIA officer aside. "He wasn't supposed to know that," the CIA case officer told his superior. "He wasn't supposed to find a flaw."

The CIA case officer couldn't believe the senior CIA officer's answer, but he managed to keep his fears from the Russian, and continued to train him for his mission.

After their trip to San Francisco, the case officer handed the Russian a sealed envelope with the nuclear blueprints inside. He was told not to open the envelope under any circumstances. He was to follow the CIA's instructions to find the Iranians and give them the envelope with the documents inside. Keep it simple, and get out of Vienna safe and alive, the Russian was told. But the defector had his own ideas about how he might play that game.

The CIA had discovered that a high-ranking Iranian official would be travelling to Vienna and visiting the Iranian mission to the IAEA, and so the agency decided to send the Russian to Vienna at the same time. It was hoped that he could make contact with either the Iranian representative to the IAEA or the visitor from Tehran.

In Vienna, however, the Russian unsealed the envelope with the nuclear blueprints and included a personal letter of his own to the Iranians. No matter what the CIA told him, he was going to hedge his bets. There was obviously something wrong with the blueprints - so he decided to mention that fact to the Iranians in his letter. They would certainly find flaws for themselves, and if he didn't tell them first, they would never want to deal with him again.

The Russian was thus warning the Iranians as carefully as he could that there was a flaw somewhere in the nuclear blueprints, and he could help them find it. At the same time, he was still going through with the CIA's operation in the only way he thought would work.

The Russian soon found 19 Heinstrasse, a five-storey office and apartment building with a flat, pale green and beige facade in a quiet, slightly down-at-heel neighbourhood in Vienna's north end. Amid the list of Austrian tenants, there was one simple line: "PM/Iran." The Iranians clearly didn't want publicity. An Austrian postman helped him. As the Russian stood by, the postman opened the building door and dropped off the mail. The Russian followed suit; he realised that he could leave his package without actually having to talk to anyone. He slipped through the front door, and hurriedly shoved his envelope through the inner-door slot at the Iranian office.

The Russian fled the mission without being seen. He was deeply relieved that he had made the hand-off without having to come face to face with a real live Iranian. He flew back to the US without being detected by either Austrian security or, more importantly, Iranian intelligence.

Just days after the Russian dropped off his package at the Iranian mission, the National Security Agency reported that an Iranian official in Vienna abruptly changed his schedule, making airline reservations to fly home to Iran. The odds were that the nuclear blueprints were now in Tehran.

The Russian scientist's fears about the operation seemed well founded. He was the front man for what may have been one of the most reckless operations in the modern history of the CIA, one that may have helped put nuclear weapons in the hands of a charter member of what President George W Bush has called the "axis of evil".

Operation Merlin has been one of the most closely guarded secrets in the Clinton and Bush administrations. It's not clear who originally came up with the idea, but the plan was first approved by Clinton. After the Russian scientist's fateful trip to Vienna, however, the Merlin operation was endorsed by the Bush administration, possibly with an eye toward repeating it against North Korea or other dangerous states.

Several former CIA officials say that the theory behind Merlin - handing over tainted weapon designs to confound one of America's adversaries - is a trick that has been used many times in past operations, stretching back to the cold war. But in previous cases, such Trojan horse operations involved conventional weapons; none of the former officials had ever heard of the CIA attempting to conduct this kind of high-risk operation with designs for a nuclear bomb. The former officials also said these kind of programmes must be closely monitored by senior CIA managers in order to control the flow of information to the adversary. If mishandled, they could easily help an enemy accelerate its weapons development. That may be what happened with Merlin.

Iran has spent nearly 20 years trying to develop nuclear weapons, and in the process has created a strong base of sophisticated scientists knowledgeable enough to spot flaws in nuclear blueprints. Tehran also obtained nuclear blueprints from the network of Pakistani scientist Abdul Qadeer Khan, and so already had workable blueprints against which to compare the designs obtained from the CIA. Nuclear experts say that they would thus be able to extract valuable information from the blueprints while ignoring the flaws.

"If [the flaw] is bad enough," warned a nuclear weapons expert with the IAEA, "they will find it quite quickly. That would be my fear"