The Jerusalem Talmud, Brachot 9:5, says that David could not deal with his evil inclination, so he killed it in his heart.
How does one understand this passage? How did David kill his evil inclination?
Mi Yodeya is a question and answer site for those who base their lives on Jewish law and tradition and anyone interested in learning more. It only takes a minute to sign up.Sign up to join this community
See Tanya Chapter 1 (which alludes to this Yerushalmi), which is explained in detail in Chapter 10.
In short killing it means the inclination for evil has no expression for its energy, no life. It is dead because it has no expression, yet it is not turned over to good because the Tzaddiks love for Hashem is not complete, thus not completely transformative. Turning it to good (as described in the Yerushalmi, a quality of Avraham Avinu) means that the connection to evil is completely removed and therefore the energy of the Yetzer Harah is dedicated to good completely.
(See also particularly footnote 3 in the above link.)
So the fundamental answer of how did he slay his evil inclination is by arousing such a great love for Hashem that it completely removed any desire for evil, but wasn't quite enough to turn that energy towards good. [The basic thesis in Tanya is that not everyone can do even that, and the ability to do it the way Dovid HaMelech did it or to do it completely requires a G-d given potential that is not available to the average person. The average person has the ability to never sin in thought, speech or action, but is not able to transform his or her innate desires].
Although there is no single technique for accomplishing this, in Chapter 1 it says that he killed it through fasting. On this the Lubavitcher Rebbe comments that the Zohar Chadash says that he killed it through learning, so it seems that the Baal HaTanya had version of the Yerushalmi included explicitly that he killed it through fasting. The context of the verse that shows that he killed it continues "My knees stumbled from fasting ..."
לא היה יכול לעמוד בו וכו'. ר"ל לעשות שלום עמו והרגו כפה אותו בתענתים ובתורה ובשירים ותשבחות לעשות רצון בוראו:
He could not with stand it etc. Which is to say make peace with it. And he killed it; he forced it with fasts and Torah study and songs and praises to do the will of his Creator.