The 10-line poem - written a year before the writer died in 1990 and reproduced in today's TES - was addressed to pupils at the Priory school, Dorset.
It depicts the punishments inflicted by a history teacher on pupils who do not remember significant dates. But, it concludes, Priory pupils should praise their own teachers, who have no such unfortunate habits.
Liz Whittingham, archivist at the Roald Dahl Centre, said: "Roald Dahl thought that sending a poem was much more fun than a standard letter. This is one of about a dozen poems that he sent to schools."
Dated June 21 1989, and typed on headed notepaper, the poem is signed with love from Roald Dahl. It was sent to Year 3 pupils in response to letters they had written to the author. While included in the archives of the Roald Dahl Centre, the verse has not appeared in print till today.
Jenny Sibbold, the teacher who received the letter, said: "Roald Dahl has always been a hero of mine. I was just so delighted he'd written back, the value of the letter didn't occur to me."
After reading the poem to her class, she took it home. She stored it with some papers at home then forgot about it. Earlier this month, she retrieved it for an assembly marking national poetry day.
Head Mark Loveys said: "We were flabbergasted. A Roald Dahl poem that hasn't hit the bookshelves is a real feather in our cap."
Roald Dahl wrote more than 50 books, including Charlie and the Chocolate Factory and Matilda. More than 30 million of his books have been sold nationally, with a million more selling every year.