THE first rule of spying is not to get found out. Stealing a foreign country’s secrets necessarily involves telling lies and breaking their laws. Now America seems to have been caught at two types of spying in Europe, and it looks dreadful.

The first charge is that it has tapped the mobile phone of Angela Merkel, Germany’s chancellor—one of up to 35 world leaders it has apparently been bugging (see article). The second is that it hoovers up vast amounts of information about European citizens’ communications: collecting haystacks in case it later needs to look for needles. News of both has come from Edward Snowden, a former contractor for America’s National Security Agency (NSA) who has taken refuge in Russia.

The leaks have caused deep anger, especially among Germans, who hear echoes of the Gestapo and the East German Stasi. Many in France and Spain are also outraged that a close ally like America should presume to spy on them. Barack Obama says he did not know that people in the NSA were bugging his friend the chancellor. Earlier leaks suggested that the NSA has weakened commercial cryptography to make spying easier. Now it appears that the NSA has hacked into the “cloud” run by Google and other big American firms. Alarmed that the spooks are out of control, Dianne Feinstein, one of the NSA’s main congressional backers, has promised an inquiry to run alongside the president’s own review.

Mounting distrust makes a reckoning essential. For its own sake, the NSA needs a new start, under new leaders and with proper oversight. But for the sake of the Americans whom the NSA must protect, neither Congress nor the White House should succumb to a dangerous mood of retribution.

Friendless fortress

For a start, it turns out that some of Mr Snowden’s evidence was radically misinterpreted: much of the hoovering has in fact been undertaken by European spies on non-Europeans and then passed to the NSA. This was to protect the West from Islamist terror, which the Americans are often best-placed to investigate. That European leaders did not know of this before complaining to Mr Obama suggests that their lack of intelligence oversight is at least as bad as his.

Second, spying on allies is not inherently wrong. Germany and France have broad overlapping national interests with America—but they occasionally clash. Before the war in Iraq Jacques Chirac, then France’s president, and Gerhard Schröder, Mrs Merkel’s predecessor, sought to frustrate America’s attempts to win over the UN Security Council. Europeans spy on Americans, too, as Madeleine Albright found when she was secretary of state. Politicians think inside information gives them an edge, even when negotiating with friends. After today’s outcry has died away, that will remain true.

But the promised gains from espionage need to be measured against the costs and likelihood of being caught. In the past, electronic spying was seen as remote and almost risk-free. In an era of endemic leaks, however, the risks of intrusive eavesdropping are higher. Relations between America and its allies have suffered. The row may get in the way of international agreements, such as a transatlantic free-trade deal. It could lead to the fragmentation of the internet, enabling more government control by countries such as China and Russia. Bugging someone as vital to America as the German chancellor is too important a decision to be left to a spymaster. It is a political choice—and, without a specific aim in mind, it will usually be a no-no.

America should make it clear that it takes abuse of intelligence-gathering seriously. Officials who lie to Congress should be fired. James Clapper, the director of national intelligence, who flatly denied that the NSA collected dossiers on “millions of Americans”, is damaged goods. NSA employees who break the law should be prosecuted, not (as in cases of those caught spying on their personal love interests) simply disciplined. America should also reaffirm that for the NSA to pass secrets to American firms for commercial advantage is illegal. Anyone concerned by Chinese state-sponsored commercial espionage cannot complain if they are thought no better.

Foreign politicians may know that their own security (notably in counter-terrorism) often benefits from American help. But they do not like the terms on which it comes. They want tighter controls on the NSA’s work and more insight into the results. America should soothe, not scoff. It should look again at intelligence-sharing and data-protection rules. Nobody expects America to give up spying. But it should examine the means and the results with a sharper eye for the broader national interest.