PARIS – “The 120 Days of Sodom,” by the Marquis de Sade, is one of the most perverse works of 18th-century literature. It is also considered a national cultural treasure of France.

Now, after decades of legal contortions and disputes over ownership, it has returned home and will be put on public display in September to mark the bicentenary of Sade’s death.

Sade wrote the rambling, unfinished draft in tiny script on both sides of narrow sheets of paper in 1785 when he was a prisoner in the Bastille. He glued the sheets together into a 39-foot-long roll and hid it in his cell. The manuscript was discovered following the storming of the Bastille on July 14, 1789.

“120 days” describes a range of violent sexual acts in detail as well as incest, torture, rape, murder, infanticide and bestiality.

The Bibliothèque Nationale de France, the National Library of France, negotiated long and hard to buy it, but lost out to Gérard Lhéritier, the Paris-based president of Aristophil, a firm specializing in rare manuscripts. Mr. Lhéritier bought it for 7 million euros, or about $9.6 million. The news of the sale was announced by Mr. Lhéritier this week.

The money is being paid to the family of Gérard Nordmann — a Swiss collector of erotica who is, according to a court ruling in Switzerland, its legal owner — and to Carlo Perrone, an Italian newspaper publisher and heir to a direct descendant of Sade who inherited the manuscript.

“We are pleased that the legal status of the manuscript has been resolved and that it has been returned to France,” Bruno Racine, the president of the National Library said in a statement. “It is part of France’s cultural heritage. And we hope that one day — even if it is years from now — it will be preserved in France’s national library.”