Britain today granted a posthumous royal pardon to computer pioneer and World War II codebreaker Alan Turing, who committed suicide after his conviction in 1952 for homosexuality.

Often hailed as the “father of modern computing”, Turing played a key role in breaking Germany’s naval messages encrypted in the “Enigma” code, an effort that some historians say ensured the early end of World War II.

He died in 1954 after eating an apple laced with cyanide, two years after he was sentenced to chemical castration for the “gross indecency” of homosexuality, a crime in Britain at that time.

Turing lost his job at Britain’s electronic eavesdropping agency GCHQ after his conviction. A GCHQ spokesperson today said the agency was “delighted about the pardon” granted under the Royal Prerogative of Mercy after a request by Justice Minister Chris Grayling.

Queen Elizabeth II has pardoned Turing for “a sentence we would now consider unjust and discriminatory”, Grayling said.

Homosexuality was decriminalised in Britain in 1967.

In Britain, pardons are usually granted only when the person is innocent of the offence and when it is requested by someone with a vested interest, such as a family member.

Turing’s pardon is extremely rare as it has been granted despite neither of these conditions being met.

“A pardon from the Queen is a fitting tribute to an exceptional man,” Grayling said.

Prime Minister David Cameron said the code-breaker’s work had saved “countless lives”.

“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,” he said.

Lord Sharkey, a Liberal Democrat peer who wrote a Bill calling for a royal pardon in July 2012, said the decision was “wonderful news”.

“This has demonstrated wisdom and compassion. It has recognised a very great British hero and made some amends for the cruelty and injustice with which Turing was treated,” he said.

In December 2011, an online petition was created asking for Turing to be pardoned. It received over 34,000 signatures but was denied by the then justice secretary, Lord Tom McNally, who said Turing was “properly convicted” for what was at the time a criminal offence.

Prior to that in August 2009, a petition won an official apology from then British premier Gordon Brown, who said the way Turing was persecuted over his homosexuality was “appalling”.

Turing’s efforts to break the Enigma code, used to encrypt communications between German submarines in the North Atlantic ocean, were virtually unknown to the public at the time of his death, as his work was kept secret until 1974.

Turing also published pioneering work on early computers, writing in a 1936 paper of a “universal Turing machine”.

He told his peers that he was trying to “build a brain”.

His theory was the first to consider feeding programmes into a machine as data, allowing a single machine to perform the functions of many — just like today’s computers.