On 17 December 1888 Nikolai Khudekov asked Chekhov to write a story for Peterburgskaya Gazeta which he was an editor of. Chekhov came up with "The Cobbler and the Devil" (published on 25 December) and informed Alexey Suvorin of that. Suvorin, the Novoye Vremya's editor, took it almost as an insult, so Chekhov promised to produce a similar kind of fable for this newspaper before the New Year Eve. He started writing it on 22 December, and on the 30th sent the story by post.
Divided into three parts, it appeared in the 1 January 1889, No. 4613 issue of Novoye Vremya, titled "Fairytale" (Сказка). With a new title, "The Bet", revised and cut (part 3 of the original text now has gone) it was included in Volume 4 of Chekhov's Collected Works, published in 1899–1901 by Adolf Marks. "As I was reading the proofs, I came to dislike the end, it occurred to me that it was too cold and cruel," he explained the reason for the omission in 1903.