The first line of Anna Karenina ("All happy families are alike; each unhappy family is unhappy in its own way.") is Tolstoy's philosophy in a nutshell, and in this novel he explores the attitudes he was beginning to live out. He was always more philosopher than artist, and he used his novels to experiment with life. Anna Karenina is also a tragic love story, with some extremely iconic scenes (particularly those involving trains).
Critics focus on Anna's sin contrasted by Levin's spirituality, but Tolstoy never limits himself by these terms. Levin isn't pure mind, and Anna isn't pure body. They don't even have a lot to do with each other in most of the novel. The plot is convoluted—everyone's having an affair, or wants to have an affair, or is the victim of someone else's affair. Anna holds other relationships together and loses her own; even Levin, the moral figure, can't keep himself untainted.
This is Tolstoy's grudging admission that no life is perfect. Levin is Tolstoy, and even he is unable to free himself from a prosaic life that keeps him from peace. Levin's desire to do good and renounce earthly wealth leads him to flee society and his own family; he finds contentment in work and quiet pursuit of God. Tolstoy later imitated Levin, becoming more distant from his wife and children, until he died at a train station running away from home.
Perhaps Levin's brief happiness at the end of the novel was the reflection of a similar desire on Tolstoy's part, whose increasingly erratic behavior had alienated everyone. The families in Anna Karenina are fictional, but their general malaise of unhappiness closely reflects that of Tolstoy's own family. In many ways this is the mea culpa of one whose attempts to follow his own conscience were the actions of a brilliant man torn between a desire for God and the urges of the flesh.
And what about Anna? Her demise casts death as the most complete experience, and the one most closely mirroring life. For Anna and those around her, death brings closure and forgiveness, even as it brings judgment and chaos. That the novel ends with Levin rather than Anna shows up Tolstoy's actual faith. Even a misanthropist of his proportions preferred humanity to God, and Anna Karenina is his love poem to it, and his most bitter condemnation of his fellows.