It is narrated from Sayyidah Aishah (may Allah be pleased with her) that the beloved Prophet (peace and blessings be upon him) said: "No affliction befalls a believer except that, in return for it, Allah, Glorified is He, wipes away his sins, even by a thorn that hurts him."
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الجنائز / 6538