II Samuel 16:5-14
And king David came to Bahurim and, behold, there came out of there a man from the family of the house of Saul, whose name was Shimei, the son of Gera, coming forth and cursing. And he threw stones at David, and at all king David's servants and at all the people and at all the mighty men who were on his right and on his left hand. And so said Shimei in his curse, "Begone, begone, you man of blood, and you wicked man. The Lord has returned upon you all the blood of the house of Saul, in whose stead you have reigned; and the Lord has given the kingdom into the hands of Absalom your son; and behold you are in your own evil for you are a man of blood." And Abishai the son of Zeruiah said to the king, "Why should this dead dog curse my lord the king? let me go over, I beg you, and remove his head." And the king said, "What is it between me and you, sons of Zeruiah? So let him curse, because the Lord has [surely] said to him, 'Curse David'; who then shall [have the right to] say, 'Why have you done so'?" And David said to Abishai and to all his servants, "Behold my son who came from my body seeks my life; how much more now [that] the Benjamite [should do it]? let him alone, and let him curse; for the Lord has bidden him. Perhaps the Lord will see (the tears of) my eye, and the Lord will return to me good instead of his curse on this day." And David and his men went by the road; and Shimei went along the hillside opposite him, going and cursing and he threw stones toward him, and he threw earth. And the king, and all the people that were with him were weary, and he refreshed himself there.
(Translation via Chabad.org)
Shimi ben Gera was actively hurling insults at King David, Hashem's anointed, but when Abishai suggests to David that he [Shimi] be executed, David insists not, and spares his life.
However, later, in I Kings 2:9, David charges his heir Shlomo with the task of taking revenge on Shimi ben Gera for what he did.
And, behold, there is with you Shimei the son of Gera the Benjamite of Bahurim, who cursed me with a grievous curse on the day when I went to Mahanaim, and he came down to meet me at the Jordan, and I swore to him by the Lord, saying, 'I will not put you to death with the sword.' And now hold him not guiltless, for you are a wise man, and you will surely know what you ought to do to him, and you shall bring his hoary head down to the grave with blood."
There seems to be a big contradiction here. First, David spares Shimi's life, but then later he tells his son Shlomo to execute him because of his actions. Why? Perhaps David took an oath that Shimi would not die in his lifetime but that after he died Shimi would be charged and executed?