Bulgakov started writing the novel in 1928, but burned the first manuscript in 1930, seeing no future as a writer in the Soviet Union. He restarted the novel in 1931. In early 1920's Bulgakov visited atheistic-propaganda journal redaction meeting, which was transformed by Bulgakov into the Walpurgis Night ball of the novel. The second draft was completed in 1936, by which point all the major plot lines of the final version were in place. There would follow four other versions. Bulgakov stopped writing four weeks before his death in 1940, leaving the novel with some unfinished sentences and loose ends.
A censored version, with about 12 percent of the text removed and still more changed, was first published in Moscow magazine (no. 11, 1966 and no. 1, 1967). The YMCA Press in Paris, best celebrated for publishing the work of Aleksandr Solzhenitsyn published the first book edition. The text of all the omitted and changed parts, with indications of the places of modification, was printed and distributed by hand (in a dissident practice known as samizdat). In 1969, the publisher Posev (Frankfurt) printed a version produced with the aid of these inserts.
In the Soviet Union, the first complete version, prepared by Anna Saakyants, was published by Khudozhestvennaya Literatura in 1973, based on the version completed at the beginning of 1940, as proofread by the publisher. This version remained the canonical edition until 1989, when the last version, based on all available manuscripts, was prepared by Lidiya Yanovskaya.