WHO would have thought that a friendless theocracy with a Holocaust-denying president, which hangs teenagers in public and stones women to death, could run diplomatic circles around America and its European allies? But Iran is doing just that. And it is doing so largely because of an extraordinary own goal by America's spies, the team behind the duff intelligence that brought you the Iraq war.

It doesn't take a fevered brain to assume that if Iran's ayatollahs get their hands on the bomb, the world could be in for some nasty surprises. Iran's claim that its nuclear programme is entirely peaceful is widely disbelieved. That is why Russia and China joined America, Britain, France and Germany at the UN Security Council to try to stop Iran enriching uranium. Until two months ago they seemed ready to support a third and tougher sanctions resolution against Iran. But then America's spies spoke out, and since then five painstaking years of diplomacy have abruptly unravelled (see article).

The intelligence debacle over Iraq has made spies anxious about how their findings are used. That may be why they and the White House felt it right to admit, in a National Intelligence Estimate in December, that they now think Iran halted clandestine work on nuclear warheads five years ago. As it happens, this belief is not yet shared by Israel or some of America's European allies, who see the same data. But no matter: the headline was enough to pull the rug from under the diplomacy. In Berlin last month, the Russians and Chinese made it clear that if there is a third resolution, it will be a mild slap on the wrist, not another turn of the economic screw.

At the same time, Iran is finding an ally in the International Atomic Energy Agency (IAEA). Its director-general, Mohamed ElBaradei, is a Nobel peace-prize winner who is crusading to confound those he calls “the crazies” in Washington by helping Iran to set its nuclear house in order, receive a clean bill of health and so avert the possibility of another disastrous war.

Honest spies, a peace-loving nuclear watchdog. What can be wrong with that? Nothing: unless the honesty of the spies is deliberately misconstrued and the watchdog fails to do its actual job of sniffing out the details of Iran's nuclear activities.

Thanks for letting us off

Beaming like cats at the cream, a posse of Iranians went to January's World Economic Forum in Davos claiming a double vindication. Had not America itself now said that Iran had no weapons programme? Was not Iran about to give the IAEA the answers it needed to “close” its file? In circumstances like these, purred Iran's foreign minister, there was no case for new sanctions, not even the light slap Russia and China prefer.

Yet Iran's argument is a travesty. Although the National Intelligence Estimate does say that Iran probably stopped work on a nuclear warhead in 2003, it also says that Iran was indeed doing such work until then, and nobody knows how far it got. The UN sanctions are anyway aimed not at any warhead Iran may or may not be building in secret, but at what it is doing in full daylight, in defiance of UN resolutions, to enrich uranium and produce plutonium. We need this for electricity, says Iran. But it could fuel a bomb. And once a country can produce such fuel, putting it in a warhead is relatively easy.

Some countries, it is true, are allowed to enrich uranium without any fuss. The reason for depriving Iran of what it calls this “right” is a history of deception that led the IAEA to declare it out of compliance with its nuclear safeguards. So it is essential that Mr ElBaradei's desire to end this confrontation does not now tempt him to gloss over the many unanswered questions. With a lame duck in the White House and sanctions unravelling, Iran really would be home free then.

Would it be so tragic if a tricky Iran were to slip the net of the Nuclear Non-Proliferation Treaty? North Korea quit the treaty and carried out a bomb test in 2006. Israel never joined, saying coyly only that it won't be the first to “introduce” nuclear weapons into the region—but won't be the second either. India and Pakistan, two other outsiders, have already strutted their stuff. Why should one more gate-crasher spoil the party?

One obvious danger is that a nuclear-armed Iran, or one suspected of being able to weaponise at will, could set off a chain reaction that turns Saudi Arabia, Egypt, Syria, even Turkey rapidly nuclear too. America and the Soviet Union, with mostly only their own cold war to worry about, had plenty of brushes with catastrophe. Multiplying Middle Eastern nuclear rivalries would drive up exponentially the risk that someone could miscalculate—with dreadful consequences.

Time for Plan B

For some this threat alone justifies hitting Iran's nuclear sites before it can build the bomb they fear it is after. But if Iran is bent on having a bomb, deterrence is better. Mr Bush has already said that America will keep Israel from harm. By extending its security umbrella to Saudi Arabia and Egypt, America might stifle further rivalry before the region goes critical.

Much better, however, to avoid a nuclear Iran altogether. Mr Bush says diplomacy can still do this. It is hard to see how. But he does have one card up his sleeve: the offer of a grand bargain to address the gamut of differences between America and Iran, from the future of Iraq to the Middle East peace process. So far Iran's leaders have brushed aside America's offer of talks “anytime, anywhere” and about “anything” by pointing to the condition attached: that Iran first suspend its uranium enrichment. Strangely enough, the best way to put pressure on Iran's rulers now is for America to drop that rider.

There would need to be a time limit or Iran could simply enrich on regardless, with what looked like the world's blessing. Similarly Russia and China would need to agree to much tougher sanctions to help concentrate minds. Iran's leaders may still say no. But the ayatollahs would have to explain to ordinary Iranians why they should pay such a high price in prosperity forgone for making a fetish out of not talking, and out of technologies that aren't even needed to keep the lights on. If Iran's leaders cannot be persuaded any other way, perhaps they can be embarrassed out of their bomb plans.