Intending Good

Asma'i related: "I was with a man from the inhabitants of Sham (Syria) and was attempting to appease him in a certain manner when a seller with a bucketful of pomegranates passed by us. To my surprise, my companion who was of the noble aristocrats of Sham quickly snatched a pomegranate and slipped it into his sleeve. I could not believe what my eyes had witnessed until we happened to pass by a beggar. This man from Sham brought back out the hidden pomegranate from his sleeve and handed it to the beggar. I questioned him about this strange action."
The man from Sham replied, "Do you not understand that taking the pomegranate was one evil deed and giving it to the beggar equates to ten good deeds?"

Asma'i responded, "Do you know that the taking of it (pomegranate) was an evil action and the good of giving it was not accepted of you because it was Haraam (forbidden)."

Moral

This story teaches us that the principle of 'the end justifies the means' doesn't exist within Islam. For an action to be accepted in Islam it has to fulfil two conditions, the first one is a good intention, which the man from Syria fulfilled. The second condition is that the action must be in accordance with the Qur'an and Sunnah otherwise it will be rejected, this was the principle that the man from Syria didn't fulfil and thus his good deed will be rejected. Both conditions must be fulfilled, merely having a good intention isn't enough.