Whoever is sincere to Allah, Allah will safeguard him against evil and indecency. He will guard against them via means that he is not even aware of, and he will come between him and the routes leading to destructive sin. Ma’ruf al-Karkhi once saw some youths preparing themselves to go forth for battle at a time of fitna and said, ‘O Allah, preserve them!’ It was asked of him, ‘Why are you supplicating for them?’ He replied, ‘If He were to preserve them, they would not leave to carry out what they intend.’
Umar heard a person saying, ‘O Allah, you intervene between a person and his heart, so intervene between me and my disobeying You.’ This pleased Umar and he supplicated for that person.
In exegesis to the saying of Allah, Most High,
“Know that Allah intervenes between a man and his heart.” (al-Anfal 8:24)
Ibn Abbas said, “He intervenes between the believer and (his committing) sins that would drag him into the Fire.’ (Tabari)
One of the previous people performed Hajj, while sleeping at Mecca with a group of people, he had a sudden urge to commit a sin and heard a voice crying out, ‘Woe to you! Are you not performing Hajj?!’ Hence Allah guarded him against perpetrating the sin.
One person went out with a group of people desiring to commit a sin, when he was about to do it, a voice cried out,
“Every self is held in pledge against what it has earned.” (al-Muddathir 74:38)
and so he abandoned it.
A man entered a thicket dense with trees and said, ‘I could commit my sin here in secret, who is there to see me?’ He then heard a voice reverberating throughout the ticket (reciting the verse),
“Does He who created not then know? He is the All-Prevading, the All-Aware.” (al-Mulk 67:14)
Another desired to commit a sin and left to carry it out. When walking, he passed by a story teller plying his trade amongst the people. He stood there listening and heard him saying, ‘O you who desire to commit a sin! Do you not know that the Creator of desires is fully aware of your intent?’ At this he fell in a swoon and when he regained consciousness, immediately repented.
One of the righteous kings had fallen in love with a beautiful subject of his. He feared for himself and so stood in prayer at night, seeking succour with Allah. That same night, the subject fell ill and passed away three days later.
The Legacy of the Prophet Ibn Rajab Al-Hanbali p 44-46