A copy of The Importance of Being Earnest, inscribed by the author to the man who allowed him access to books, expected to fetch thousands

An edition of The Importance of Being Earnest personally inscribed by Oscar Wilde to the prison governor who the playwright said did him "a great and noble kindness" in allowing him access to reading and writing materials will be auctioned for thousands of pounds this summer.

Wilde was found guilty of gross indecency in May 1895, and moved from Wandsworth prison to Reading gaol that November, where his stay was overseen initially by prison governor Henry Isaacson, a man Wilde said had "the soul of a rat". The author had feared he was losing his mind under Isaacson's regime, writing to the home secretary of "the fearful system of cellular confinement", the absence of writing materials, and the absence of books which he called "so vital for the preservation of mental balance".

The prisoner, wrote Wilde – in an echo of today's ban on prisoners being sent books by their families – "is deprived of everything that could soothe, distract, or heal a wounded and shaken mind", and "horrible as all the physical privations of modern prison life are, they are as nothing compared to the entire privation of literature to one to whom Literature was once the first thing of life, the mode by which perfection could be realised, by which, and by which alone, the intellect could feel itself alive".

When Major James Nelson took over from Isaacson, he immediately gave Wilde access to books; the new governor is said to have told Wilde: "The Home Office has allowed you some books. Perhaps you would like to read this one. I have just been reading it myself."

Wilde is said, in Thomas Wright's biographical study Oscar's Books, to have broken down and wept at the words, "the first kind words that have been spoken to me since I have been in [Reading] gaol". Nelson also allowed his most famous prisoner to begin writing again – Wilde would go on to pen De Profundis while in Reading gaol, the letter to his former lover Lord Alfred Douglas in which he writes of how "I have lain in prison for nearly two years. Out of my nature has come wild despair; an abandonment to grief that was piteous even to look at; terrible and impotent rage; bitterness and scorn; anguish that wept aloud; misery that could find no voice; sorrow that was dumb."

Nelson bent the rules for Wilde – all written material was meant to be handed to the authorities each evening, but he would let Wilde consult his previous work to keep the thread of his writing, and when the author was released in 1897, Nelson returned the whole manuscript to him.

Wilde described Nelson elsewhere as "the most Christlike man I ever met", and in the specially printed copy of The Importance of Being Earnest – number 13 of just 100– has written: "To Major Nelson: from the author. A trivial recognition of a great and noble kindness. Feb, 99." The copy of the play is to be auctioned by Bonhams in London on 18 June, and is expected to fetch up to £60,000.

"This inscribed edition of The Importance of Being Earnest is a poignant reminder of the very real hardship which Wilde suffered in prison and the enormous difference which Major Nelson's acts of common humanity made to the writer's morale and health," said Bonhams head of books Matthew Haley. "It is arguable that the governor saved Wilde's life and almost certain that without him there would have been no De Profundis."

The Importance of Being Earnest was the last work written by Wilde before his conviction. It opened on Valentine's Day 1895 and closed after just 56 performances despite its huge success, after the author went on trial, and was not published until 1899, just a year before Wilde died.

In 1898, Wilde had sent Nelson a copy of The Ballad of Reading Gaol, the poem he wrote in exile in France about a prisoner who is condemned to death, and how he "looked / With such a wistful eye / Upon that little tent of blue / Which prisoners call the sky." Wilde wrote in that copy: "Major Nelson from the Author. In recognition of many acts of kindness and gentleness Feb.98".