Written over a seven-year period from 1914 to 1921, the novel was serialised in the American journal The Little Review from 1918 to 1920, when the publication of the Nausicaä episode led to a prosecution for obscenity. In 1919, sections of the novel also appeared in the London literary journal, The Egoist, but the novel itself was banned in the United Kingdom until the 1930s. The novel was first published in its entirety by Sylvia Beach in February 1922, in Paris.
The 1920 prosecution in the US was brought after The Little Review serialised a passage of the book dealing with the main character masturbating. Legal historian Edward de Grazia has argued that few readers would have been fully aware of the orgasmic experience in the text, given the metaphoric language. Irene Gammel extends this argument to suggest that the obscenity allegations brought against The Little Review were influenced by the Baroness Elsa von Freytag-Loringhoven's more explicit poetry, which had appeared alongside the serialization of Ulysses. The New York Society for the Suppression of Vice, which objected to the book's content, took action to attempt to keep the book out of the United States. At a trial in 1921 the magazine was declared obscene and, as a result, Ulysses was effectively banned in the United States. Throughout the 1920s, the United States Post Office Department burned copies of the novel.
In 1933, the publisher Random House and lawyer Morris Ernst arranged to import the French edition and have a copy seized by customs when the ship was unloaded, which it then contested. In United States v. One Book Called Ulysses, U.S. District Judge John M. Woolsey ruled on 6 December 1933 that the book was not pornographic and therefore could not be obscene, a decision that was called "epoch-making" by Stuart Gilbert. The Second Circuit Court of Appeals affirmed the ruling in 1934. The US therefore became the first English-speaking country where the book was freely available. Although Ulysses was never banned in Ireland, neither was it available there.