British Prime Minister Gordon Brown apologized Friday for the "inhumane" treatment of Second World War code-breaker Alan Turing, who was convicted of gross indecency for being homosexual at a time when it was illegal in Britain.

A mathematician, Turing helped crack Nazi Germany's Enigma communications code, which was a turning point in the war.

He was later convicted of gross indecency for having sex with a man and forcibly treated with female hormones to reduce his sex drive. Turing committed suicide in 1954 at the age of 41.

Turing was also known for his pioneering work on artificial intelligence and computer science, including his development of the "Turing Test" to measure whether a machine can think. One of the most prestigious honors in computing, the $250,000 US Turing Prize, is named for him.

"The debt of gratitude he is owed makes it all the more horrifying, therefore, that he was treated so inhumanely .… We're sorry, you deserved so much better," Brown said in his apology published Friday in the Daily Telegraph newspaper, as well as on the prime minister's office website.

The apology comes after an internet petition garnered more than 30,000 signatures supporting the move.

Gay rights campaigner Peter Tatchell said the apology was "most welcome and commendable."

With files from The Associated Press