The marquis wrote the novel during his incarceration at the Bastille in 1785 on a long narrow scroll. He was forced to abandon the scroll when he was moved by the prison governor right before the French Revolution in 1789. After having been found, and kept in the same family's possession until the end of the 19th century, it ended up in Germany where de Sade's biographer, the psychiatrist Ivan Bloch published it for the first time under the pseudonym Eugéne Dühren.
On the title page of the first edition the publication location is marked as Paris, but this is false; it was actually published in Berlin.