2 Samuel 16:5
And when king David came to Bahurim, behold, thence came out a man of the family of the house of Saul, whose name was Shimei, the son of Gera: he came forth, and cursed still as he came. And when king David came to Bahurim, behold, thence came out a man of the family of the house of Saul, whose name was Shimei, the son of Gera: he came forth, and cursed still as he came.
The verse occurs as David was fleeing Jerusalem in humility and distress during Absalom's rebellion and came to Bahurim. Shimei, who met him there, was a Benjamite kinsman belonging to the family of the house of Saul. He came out cursing David continually as he came, accusing him of bloodshed, venting his anger, and throwing stones and dirt at him.
Shimei envied David because David had received the throne and honors once given to Saul. His hostility had been hidden while David prospered but became evident when David was afflicted, and he used David's distress as an occasion to vent it. In cursing the king he acted rebelliously.
David regarded Shimei's abuse as part of the punishment God had brought upon him for his own sin. That sin had given the Lord's enemies occasion to blaspheme. He accepted the rebuke humbly and trusted that God might turn the curse and affliction into a blessing. At the time he restrained his followers from killing Shimei.
When David returned after Absalom's death, Shimei confessed his wrongdoing and David spared and forgave him, choosing mercy over the revenge he could have taken. Shimei's conduct illustrates the satanic spirit that gloats over, reviles, or adds distress to someone already suffering.