From Michael Strassfeld's A Book of Life (pp. 269-270):
The Likutim Yekarim (an eighteenth-century Hasidic work) asks, if there are sparks of holiness in all things as the mystics teach, then what are the sparks of holiness in sin? It answers that the sparks are in teshuvah ["repentance"]. In the moment we realize that we have done wrong, we gain the opportunity to redeem ourselves by returning to the holy.