I have heard that on one occasion a certain monk was dwelling among the Kosalans in a forest thicket. Now at that time, he spent the day's abiding thinking evil, unskillful thoughts: i.e., thoughts of sensuality, thoughts of ill will, thoughts of doing harm.
Then the devata inhabiting the forest thicket, feeling sympathy for the monk, desiring his benefit, desiring to bring him to his senses, approached him and addressed him with this verse:
The monk, chastened by the devata, came to his senses.
See also: any of the suttas on the six recollections (e.g., SN 11.3 , AN 3.70 , AN 11.12 , AN 11.13 ); passage 36 in Wings to Awakening; "The Ten Recollections" (Study Guide).