Queen Elizabeth II has pardoned Alan Turing, the father of modern computing, who was convicted of "gross indecency" for being gay, 61 years after he poisoned himself.

The Queen granted Turing, whose theories laid the foundation for the computer age and who broke the code which helped the Allies outfox the Nazis, an official pardon on Tuesday.

Turing, whose work on artificial intelligence still informs the debate over whether machines can think, was punished by Britain in the 1950s, when homosexuality was still a criminal offence.

You take one of your greatest scientists, and you invade his body with hormones. It was a national failure. S. Barry Cooper, University of Leeds mathematician, on Turing's forced chemical castration

"Turing was an exceptional man with a brilliant mind," Justice Secretary Chris Grayling said in a prepared statement released on Tuesday.

Describing Turing's treatment as unjust, Grayling said the code breaker "deserves to be remembered and recognised for his fantastic contribution to the war effort and his legacy to science."

Turing's contributions to science spanned several disciplines, but he is perhaps best remembered as the architect of the effort to crack the Enigma code, the cypher used by Nazi Germany to secure its military communications.

Turing's groundbreaking work, combined with the effort of cryptanalysts at Bletchley Park, near Oxford, and the capture of Nazi code books, gave the Allies the edge across half the globe, helping them defeat the Italians in the Mediterranean, beat back the Germans in Africa and escape enemy submarines in the Atlantic.

Even before the war, Turing was formulating ideas that would underpin modern computing, ideas which matured into a fascination with artificial intelligence and the notion that machines would someday challenge the minds of man.

When the war ended, Turing went to work programming some of the world's first computers, drawing up one of the earliest chess games, among other initiatives.

Turing made no secret of his sexuality, and being gay could easily lead to prosecution in post-war Britain.

In 1952, Turing was convicted of "gross indecency" over his relationship with another man, and he was stripped of his security clearance, subjected to monitoring by British authorities, and forced to take estrogen to neutralise his sex drive - a process described by some as chemical castration.

S. Barry Cooper, a University of Leeds mathematician who has written about Turing's work, said future generations would struggle to understand the code breaker's treatment.

"You take one of your greatest scientists, and you invade his body with hormones," he said in a telephone interview. "It was a national failure."

Turing committed suicide in 1954.

Turing's legacy was long obscured by secrecy.

"Even his mother wasn't allowed to know what he'd done," Cooper said.

Then-Prime Minister Gordon Brown issued an apology for Turing's treatment in 2009, but campaigners kept pressing for a formal pardon.