There was a king long time ago and he had a vast kingdom. Though he had tremendous amount of wealth, but he didn't have peace of heart. So he decided to be a good Muslim. He heard that there is a very pious man who stays in a jungle and that many people go to visit him for advice. The king decided to visit him for some advice also. When he got there, he asked the pious man "How can I become pious like you?" The pious man replied that remember death 40 times a day for 40 days. The king thought that it was very easy and he thanked him and left for his palace. He remembered death 40 times a day for 40 days but no change came to his life. He was same as before.
The king became angry and called that pious man to his court. The king told him that he is nothing but a liar and that he should be killed before he fools other people. It was decided that he will be beheaded the next day. But the Pious man had a request. He asked if he could become the king for a day. He promised that after getting the command, he will not kill the previous king or do any harm to him. So, the king agreed and made the pious man the king for a day. As soon as the pious man became the king, he went to the market and saw a man selling peanuts. He told the soldiers to catch that man and bring him to the palace. So, the peanut sales man was brought to the court. The pious man told the peanut sales man that he will be killed tomorrow. The peanut sales man became frightened and dropped all his peanuts. He started crying and asked what he did. But the pious man said that he will be killed tomorrow and locked up in jail for today.
Now, as the peanut sales man knew that he is going to die, he forgot about everything else and started asking forgiveness from Allah. He started praying and doing excessive dhikir (remembrance of Allah). The Pious man ordered that the most beautiful prostitute in the city should be brought and placed in the jail with peanut sales man. She was brought and she asked the man to commit adultery with her. Now the pious man brought the previous king and told him to watch. The peanut sales man started yelling at the woman to get away because he is going to die tomorrow and this evil deed will surely cause him problems with Allah.
Then the pious man asked the previous king if he understood what is going on. The Pious man explained that when you really know that you will die, then you will surely stay away from all evil deeds and engage yourself into the worship of Allah. So, remembering death once properly would be enough to change the life of a human being.
Ofcourse, the peanut sales man was released afterwards.