(CNN) -- Alan Turing, a British code-breaker during World War II who was later subjected to chemical castration for homosexual activity, has received a royal pardon nearly 60 years after he committed suicide.
Turing was best known for developing the Bombe, a code-breaking machine that deciphered messages encoded by German machines. His work is considered by many to have saved thousands of lives and helped change the course of the war.
"Dr. Turing deserves to be remembered and recognized for his fantastic contribution to the war effort and his legacy to science," British Justice Secretary Chris Grayling said in a statement Tuesday. "A pardon from the Queen is a fitting tribute to an exceptional man."
Turing's castration in 1952 -- after he was convicted of homosexual activity, which was illegal at the time -- is "a sentence we would now consider unjust and discriminatory and which has now been repealed," Grayling said.
Two years after the castration, which Turing chose to avoid a custodial sentence, he ended his life at the age of 41 by eating an apple laced with cyanide.
Supporters have long campaigned for Turing to receive greater recognition for his work and official acknowledgment that his punishment was wrong.
An online petition in 2009 that drew tens of thousands of signatures succeeded in getting an apology from then-Prime Minister Gordon Brown for Turing's treatment by the justice system in the 1950s. Brown described the Turing sentence as "appalling."
The German messages that Turing cracked at the British government's code-breaking headquarters in Bletchley Park provided the Allies with crucial information. The German messages were encoded by Enigma machines, which Adolf Hitler's military believed made its communications impenetrable.
Turing was considered a mathematical genius.
In 1937 he published a paper introducing an idea that came to be known as the Turing machine, which is considered to have formed the basis of modern computing. This was a hypothetical device that could come up with a solution to any problem that is computable.
"Alan Turing was a remarkable man who played a key role in saving this country in World War II by cracking the German enigma code," British Prime Minister David Cameron said. "His action saved countless lives. He also left a remarkable national legacy through his substantial scientific achievements, often being referred to as the 'father of modern computing.'"
The prestigious A.M. Turing Award -- sometimes called the "Nobel Prize" of Computing -- was named after Turing.
The pardon, under the Royal Prerogative of Mercy, comes into effect Tuesday, the British Ministry of Justice said.