Video report by ITV News Nina Nannar
Alan Turing was treated in a "horrifying" manner by GCHQ, the agency said as it apologised for historic prejudice against homosexuals.
GCHQ director Robert Hannigan said the secret service failed to learn from its mistaken treatment of the genius and archaic attitudes had persisted for decades, stifling the careers of brilliant minds.
A ban on homosexuals joining the intelligence organisation remained in place into the 1990s.
At a conference hosted by equality campaigner Stonewall, Mr Hannigan told how a former spy, "Ian" - forced out of the service in the 1960s - had urged him to apologise for his treatment.
"I am happy to do so today and to say how sorry I am that he and so many others were treated in this way, right up until the 1990s when the policy was rightly changed", Mr Hannigan said.
"The fact that it was common practice for decades reflected the intolerance of the times and the pressures of the Cold War, but it does not make it any less wrong and we should apologise for it.
"Their suffering was our loss and it was the nation's loss too because we cannot know what Ian and others who were dismissed would have gone on to do and achieve. We did not learn our lesson from Turing".
Turing, known as the father of the modern computer who led the famous Bletchley Park codebreakers in their work against the Nazis, was eventually hounded from the secret service over his sexuality.
In 1954 he took his own life, but in 2013 he received a royal pardon.
"In the horrifying story of his treatment, a small ray of light is that he was not abandoned by all of his colleagues at GCHQ - many stood by him," Mr Hannigan said.