Jundub ibn Abdullah reported: The Messenger of Allah, peace and blessings be upon him, said:
كَانَ فِيمَنْ كَانَ قَبْلَكُمْ رَجُلٌ بِهِ جُرْحٌ فَجَزِعَ فَأَخَذَ سِكِّينًا فَحَزَّ بِهَا يَدَهُ فَمَا رَقَأَ الدَّمُ حَتَّى مَاتَ قَالَ اللَّهُ تَعَالَى بَادَرَنِي عَبْدِي بِنَفْسِهِ حَرَّمْتُ عَلَيْهِ الْجَنَّةَ
There was a man among those before you who had a wound. He was in such anguish that he took a knife and he slit his hand with it and the blood did not cease to flow until he died. Allah the Almighty said: My servant has taken the initiative over me by himself, so I have forbidden Paradise for him.
Source: Sahih Bukhari 3276, Grade: Sahih