In 1865, Dostoevsky was heavily in debt, having taken on his brother Mikhail's debts after he died and amassing his own through gambling. Desperate, he signed an agreement with bookseller F. T. Stellovsky, promising that if he did not hand Stellovsky a manuscript by November 1, 1866, Stellovsky would be given the rights to all Dostoevsky's past and future works. Having done this, he fled abroad to escape his creditors in July of 1865.
At this point, Dostoevsky had two works planned: "The Drunkards," which was to be a long novel concerning what he called "the current problem of drunkenness." The other sprang from an idea that had come to him in prison: an exploration of what he called "the psychological account of a crime." Dostoevsky had expected to complete "The Drunkards" quickly but instead became immersed in the second work. In September of 1865 he sent a detailed outline of it to Mikhail Katkov, the editor of the Russian Herald. His original conception of the work was as a short novel told in the first person by the criminal, who commits murder "under the influence of some of those strange, 'incomplete' ideas which go floating about in the air," as Dostoevsky put it. These "ideas" would be the radical social ideologies that gripped Russia in the 1860's, particularly Nihilism, which was emerging around the time Dostoevsky was beginning work on what would be Crime and Punishment. (The Nihilists advocated the complete destruction of the social order, without giving any theory of what would replace it.)
Dostoevsky's own experimentation with social radicalism and his consequent imprisonment and suffering had a great impact on his voice and on the development of Crime and Punishment. Much of the book's message revolves around his argument that the Western-influenced theories and emphasis on rationalism were not only incompatible with Russian society and history but even dangerous to them. The character of Raskolnikov is the vehicle through which Dostoevsky makes this point.
In December of 1865, Dostoevsky wrote to his friend Baron Vrangel that this work had grown into "a big novel, in six parts. I had much of it written and ready by the end of November. I burned it all. Now I can confess it. I wasn't pleased with it myself. A new form, a new plan captivated me and so I began over again." The new version maintained much of the hero's original characteristics, but it was not told in the first person and the plot was thickened to include the sub-stories of Dunya and Sonya.
In January 1866 the first part of the novel appeared in the Russian Herald, but Dostoevsky still had some unresolved issues to work out. His extensive notes show him still trying to develop Sonya's character (she was at one point rigorous and outspoken) and Raskolnikov's motive for committing the crime. He continued to be busy with Crime and Punishment until the fall, when he had to rush to complete The Gambler for Stellovsky and, to the great benefit of mankind and world literature, save for himself the rights to his own work. Crime and Punishment was completed in November and published to prodigious success.