It is no exaggeration to say that among the principal reasons the Allies won World War Two is that they won the Secret War first—an international duel of espionage, counter-espionage, sabotage and subterfuge. Or that for every trench-coated Continental Op and Mata Hari skulking down back alleys from Casablanca to Singapore, there were a thousand others in drab offices and laboratories, pouring over documents, devising new weapons, and deciphering the enemy's most valuable secrets.
That deciphering was crucial because the Germans and Japanese arrogantly believed their codes were unbreakable. The British got two German "Enigma" code machines from the Poles in 1939. At a highly secret think tank called Bletchley Park, mathematicians and scientists created the world's first computer. With it, and key documents captured from German warships, they cracked the German code. The operation was called Ultra—the war's best-kept secret. Until the Germans were forced back to the fatherland in 1944 (and therefore no longer needed Enigmas), Ultra provided the Allies with indispensable notice of Hitler's plans.
In the Pacific, the U.S. Army's Signal Intelligence Service had similar success cracking Japan's top code and keeping that information from the enemy. Knowing the code helped the Yanks lure the Japanese into a trap at Midway (the Allies' first great naval victory) and shoot down Admiral Yamamoto over Bougainville in 1943.
Espionage still required people in trench coats, though, and the allies had the best—in Britain, Colonel Menzies' Secret Intelligence Service (SIS), and in the States, the FBI, and especially the new Office of Strategic Services (O.S.S.), led by William J. "Wild Bill" Donovan, a WW1 hero and former U.S. Attorney. It was always a tossup whether Donovan's biggest enemies were the Germans and Japanese, or J. Edgar Hoover and the military intelligence chiefs who so resented him and his organization. Eventually employing more than 60,000 people, the O.S.S. led directly to the post-war Central Intelligence Agency.
German intelligence was generally far less successful. The first (and last) large-scale sabotage mission to the U.S. was an immediate failure, and the Germans were completely fooled as to the true location of the D-Day landings until months after the landings took place. On the other side, the Americans captured a German submarine, the U505, the day before D-Day, and the Germans didn't find out about it until 1947. That sub is on now display in Chicago.