When Richard Sorge – reputedly the greatest spy who ever lived – was executed by the Japanese on 7 November 1944 his last words were: “The Red Army!”, “The International Communist Party!” and “The Soviet Communist Party!”, all delivered in fluent Japanese to his captors. Sorge was bound hand and foot, the noose already set around his neck. Tall, blue-eyed, ruggedly good-looking and apparently unperturbed by his imminent demise, Sorge was contributing the perfect denouement to what he might well have assumed was an enduring myth in the making.

So much for the myth but, as ever, the truth – or as close as we can get to the truth – is infinitely more compelling, as this fascinating biography makes clear. Sorge, suave, calm, facing his death with enviable sangfroid was a far more complex, troubled and rackety figure than the one he cut at his execution, and is all the more interesting for it.

Born in 1895 to a German father and a Russian mother in Baku, an oil town on the Caspian Sea, Sorge had a comparatively settled bourgeois upbringing, particularly after the family moved back to Berlin when he was a young child.

What radicalised him was the First World War. He enlisted as a soldier when hostilities began and he saw a lot of action, being wounded three times. The slaughter he witnessed on the Western and Eastern fronts made Sorge embrace communism. In the near-civil war that erupted in Germany after the Armistice he joined the Spartacist revolutionaries who saw the future of Germany as a utopian workers’ republic.

Sorge’s activities were significant enough to draw the attention of the embryonic Soviet regime’s secret services, the so-called Fourth Department, a forerunner of the NKVD and the KGB. Sorge became an agent of the Comintern, the international wing of the Communist Party, and was sent briefly to Britain and then Berlin, where his diligence and zeal were duly noted. In the 1920s the Fourth Department developed its system of “rezidents”, illegal spy centres in key cities, as opposed to the “legals” who were usually working under the guise of diplomatic immunity. Sorge was sent to Shanghai in 1930 to join the apparat being established there and thus began an association with the Orient that was to endure for the rest of his life as a spy.

Shanghai suited Sorge. He was a committed communist but it didn’t stop him from living life to the full. A near-alcoholic and compulsive womaniser (even though he now had a wife, Katya, back in Moscow), he also had a passion for speed that manifested itself in the shape of powerful motorbikes. His preferred method of seduction was to take the woman he fancied on a terrifying bike ride through the streets of Shanghai before he pounced.

In fact Sorge’s spying life in Shanghai sometimes appears more like a lurid B-movie or an opera buffa. His cover was as a journalist, an implausible American called “Richard Johnson”. This was spying by the seat of the pants – perhaps only in a city like Shanghai at the time could one get away with such amateurism (one of Sorge’s agents, called Kurgan, was given the inspired code-name “Kur”) and such a concentrated number of foreign agents.

The Soviet focus was on Japan and its imperial ambitions in the puppet-state of Manchuria on the border with Siberia. Sorge’s apparat was charged with gathering as much information as possible about troop build-ups, military hardware and the risk of incursions. His cover as a journalist – he filed articles for German newspapers and magazines – allowed him to become a genuine expert. The precise, almost academic level of information and interpretation he provided added to his increasing renown.

But Sorge really came into his own when he was moved to Tokyo in 1933. Here he created a small network that soon began to achieve astonishing success. By now he was back to being Richard Sorge, freelance journalist, and his Tokyo apparat achieved the incredible double-coup of penetrating the innermost reaches of the German embassy (Sorge’s role) and the court of the Japanese prime minister, through the efforts of a Japanese journalist and government adviser he recruited called Ozaki. To make his cover more effective Sorge even joined the Nazi Party.

The German ambassador to Japan, Eugen Ott, became a close friend and trusted him absolutely. Sorge had total access to encrypted papers and German policy as relayed to the embassy. A short-wave radio was set up in a suburb and Sorge sent thousands of pages of accurate intelligence back to the Fourth Department (and therefore to Stalin himself) via a radio receiving-station in Vladivostok. Meanwhile Ozaki was able to give Sorge all the information from the militaristic faction that was driving Japanese foreign policy and imperial ambitions.

It was this access to both the crucial players on the geopolitical scene that made Sorge’s intelligence so compelling and unrivalled, and generated his greatest espionage coup. Not content with predicting the German invasion of the Soviet Union – Operation Barbarossa (duly ignored by Stalin) – Sorge was able to reassure the beleaguered Russians that Japan was both incapable of and unwilling to countenance any invasion of Siberia. Stalin’s overriding fear was of fighting a war on two fronts – against the Germans in the West and the Japanese in the East. When Sorge informed him that Japan was looking to extend its empire westwards into Indochina and beyond, Stalin was able to withdraw dozens of divisions and ordnance from the Siberian front just in time to repel the German attacks on Moscow in the winter of 1941. Without Sorge’s network’s reports and the cast-iron reassurances it gave, the course of the Second World War might have been entirely different.

But Sorge’s incredible luck was running out. A chance arrest of a minor agent and an incautious remark made in routine interrogation led to the network’s exposure and the discovery of the clandestine transmitter. Sorge’s team was rolled up and their fate determined. Right until the end Sorge was convinced the Russians would do a deal to save him but, to his bitter chagrin, he discovered he was now being ignored. He was tried and sentenced and duly hung. It was impossible for him, at his death, to be fully aware of the remarkable effect he had had on 20th-century history, and this may have generated the histrionic last-minute patriotic declarations in front of the hangman.

The fact was that Sorge had become disillusioned with communism as a result of Stalin’s ruthless purges in the 1930s (when thousands of agents were rounded up and summarily shot) and, of course, the grotesque betrayal of the Nazi-Soviet pact of 1939. Such growing cynicism, however, didn’t impede Sorge’s effectiveness. As with Kim Philby – with whom he shares many personal characteristics – the heady, addictive allure of constant duplicity and deception was enough to keep him spying.

Owen Matthews tells the story of Sorge’s extraordinary life with tremendous verve and expertise and a real talent for mise en scène. Shanghai in the 1930s and prewar Tokyo, Sorge’s stamping grounds, come vividly alive in these pages and the portrait of Sorge himself that emerges is richly authentic, giving real credence to the title’s unequivocal claim: for all his feet of clay, Richard Sorge was indeed an impeccable spy.

William Boyd’s most recent novel is “Love is Blind” (Viking)

An Impeccable Spy: Richard Sorge, Stalin’s Master Agent

Owen Matthews

Bloomsbury, 435pp, £25