Every Jew possesses seven emotional character traits, known as middos. In fact, he possesses two sets of them: Seven middos of holiness that stem from his Divine Soul, and seven middos of unholiness that stem from his Bestial Soul. It is these foul character traits that spur him to sin.
However, he need not act on every urge. The person only allows these seven undesirable middos to bring him to sin because he sort of goes crazy. He behaves irrationally. If he would be thinking clearly, he would never come to sin. As our sages say, “A man does not commit a sin unless a spirit of folly has entered into him.”
Sin is wrong, but why is it necessarily irrational?
A Jew does not want to, and cannot separate himself from G–dliness. A sin separates the Jew totally from G–d, and if the would-be sinner would realize this, he would never sin, no matter what. The only reason he sins is that he foolishly convinces himself that sinning will not affect his relationship with G–d, his Jewishness.
The only reason that this “crazy spirit” can possess the person is that G–dliness is not revealed within him. The reason for this is that he doesn’t davven seriously, or not seriously enough. Toiling in prayer reveals G–dliness in oneself and in the world. At the beginning of the day, the soul is said to be only in the person’s nose, and through prayer it is revealed throughout the body and in the world. This protects the person from the “crazy spirit,” or at least endows him with the strength to overcome it.
In fact, prayer has even greater power. Consistently toil in meditation in prayer brings the light of G–dliness to truly shine in one’s mind; this then arouses the heart to G–dliness, and reveals the Divine Soul throughout the person. Then one will never desire to sin at all, for “the strength of the soul is the weakness of the body.” The “body” here refers to the coarse desires of the Bestial Soul. When the Divine Soul dominates through consistent meditation on G–dliness, these desires are weakened to the point that they may not be able to express themselves at all (although they are still present; see Tanya ch. 13).
 Cf. Shaarei Orah, Shaar HaChanukah, 3b.
 Sotah 3a.
 ibid. ch. 24.
 ibid. ch. 14.
 Berachos 14a.
 See Tanya ch. 12.
 Zohar 1:180b. ibid. 140b.