Alan Turing.

A collection of computer genius Alan Turing’s papers have been saved for the nation by the National Heritage Memorial Fund.

The documents were to be auctioned last year but a campaign began to raise enough money for them to stay at Bletchley Park, where Turing worked during the second world war.

The rare documents are offprints of almost of all of Turing’s published work and include his handwritten notes.

The codebreaker, who killed himself after being persecuted for being gay, did not keep much of his work and few artefacts of his achievements remain.

He had given the collection to his friend and Bletchley Park colleague Professor Max Newman.

IT journalist Gareth Halfacree began the campaign to save the papers and managed to raise £23,000 from public donations. Google and a private donor also pledged significant amounts.

Today, it was announced that the National Heritage Memorial Fund had stepped in at the last minute with £213,437, the final sum needed to avoid the papers going to auction.

Dame Jenny Abramsky, chair of the National Heritage Memorial Fund, said: “This is such welcome news. Alan Turing was a true war hero and played an absolutely crucial role during the Second World War.

“The National Heritage Memorial Fund was set up in memory of those who have given their lives for the UK and this grant will now ensure that this extremely rare collection of his work stands as a permanent memorial to the man and to all those who paid the ultimate price in service to this nation.”

Simon Greenish, the chief executive of the Bletchley Park Trust, welcomed today’s announcement, saying: “The acquisition of this hugely important collection has been made possible only by the astonishing support demonstrated by the public, the media, Google, the National Heritage Memorial Fund and Christies the auctioneers, whose help in brokering the purchase is gratefully acknowledged.

“We are delighted to have the collection here at Bletchley Park, which is surely its most fitting home and it will be an incredible addition to the visitor experience.”

Next year, Manchester, Turing’s hometown, will celebrate the centenary of his birth.

Scientists, computer programmers and athletes will join efforts to celebrate his life and work.