There was a pious man among the Banu Israel who always remained busy in the worship of Allah. A group of people came to him and told him that a tribe living nearby worshipped a tree. The news upset him, and with an axe on his shoulder he went to cut down that tree. On the way, Satan met him in the form of an old man and asked him where he was going. He said he was going to cut a particular tree. Satan said, "You have nothing to be concerned with this tree, you better mind your worship and do not give it up for the sake of something that does not concern you." "This is also worship," retorted the worshipper.
Then Satan tried to prevent him from cutting the tree, and there followed a fight between the two, in which the worshipper overpowered the Satan. Finding himself completely helpless, Satan begged to be excused, and when the worshipper released him, he again said, "Allah has not made the cutting of this tree obligatory on you. You do not lose anything if you do not cut it. If its cutting were necessary, Allah could have got it done through one of his many Prophets." The worshipper insisted on cutting the tree. There was again a fight between the two and again the worshipper overpowered the Satan. "Well listen," said Satan, "I propose a settlement that will be to your advantage." The worshipper agreed, and Satan said, "You are a poor man, a mere burden on this earth. If you stay away from this act, I will pay you three gold coins everyday. You will daily find them lying under your pillow.
By this money you can fulfil your own needs, can oblige your relative, help the needy, and do so many other virtuous things. Cutting the tree will be only one virtue, which will ultimately be of no use because the people will grow another tree." This proposal appealed to the worshipper, and he accepted it. He found the money on two successive days, but on the third day there was nothing. He got enraged, picked up his axe and went to cut the tree. Satan as an old man again met him on the way and asked him where he was going. "To cut the tree," shouted the worshipper. "I will not let you do it," said Satan. A fight took place between the two again but this time Satan had the upper hand and overpowered the worshipper. The latter was surprised at his own defeat, and asked the former the cause of his success. Satan replied, "At first, your anger was purely for earning the pleasure of Allah, and therefore Almighty Allah helped you to overpower me, but now it has been partly for the sake of the gold coins and therefore you lost."
Source: From the book "Ihyaa-ul Uloom Ud Deen" by Imam Ghazzali (ra).