"The Cop and the Anthem" follows the misadventures of Soapy, a homeless man, while winter begins its approach. Due to the harshness of the winter conditions, Soapy determines to get himself arrested, so as to enjoy the shelter that incarceration would provide. He embarks on various attempts to get himself in trouble with the law, but each time it ends in failure.
However, O. Henry is known for his twist endings, and this story is no exception. In his despair, Soapy determines to turn his life around, get a job, and strive to make something out of himself. However, it is after he has come to this epiphany, loitering outside an old church, that a policeman comes around and arrests him.
This, then, is the great irony at the end of the story. All of Soapy's various attempts to get himself in trouble end in failure. It is only later, after he has experienced his change of heart, that he is finally put under arrest (but it is at a point when he no longer has any desire to be arrested at all).