The creation of evil is in no way evil, it is the committing of evil that is evil. Man is endowed with free will and God enables man's willed actions. Therefore, it is man's willing and committing evil that is evil and ugly, not God's giving objective existence to evil. If God were not to create what man wills, then human free will would be annulled.
Secondly, none of God's creations are merely one-dimensional, they pertain to the whole universe; therefore any creation should be evaluated according to its aggregate results, not merely to the act itself. To give an example, the results of rain falling are manifold, almost all being useful to mankind. If some people sustain damage from the rain due to their own miscalculation, it is not possible for them to argue that the creation of rain is not a blessing, nor can they claim that its creation is evil. Perhaps rain seems evil to them due to their personal experience. Similarly, there are numerous benefits for mankind in the creation of fire. If some people are harmed by fire due to their failure to use it appropriately they cannot say that the creation of fire is evil. Fire was not created to burn only their hands; perhaps they brought their hands too close to the fire while cooking and made a thing that normally serves us bring them harm.
As a result, a lesser evil is acceptable for the greater good. If an evil which will lead to a greater good is abandoned so that the lesser evil is eliminated, a greater evil will then have been perpetrated. For example, there is certainly some minor material and physical harm and discomfort in the drafting of soldiers to create an army to defend one's homeland, but in this there is a greater benefit in that the whole country is saved from invasion. If the defense of a country is abandoned in order to avoid such minor discomforts then the greater benefit will be lost and a greater evil will follow. This is most definitely a mistake. Likewise, to amputate a finger that is gangrenous is good and right, although it is ostensibly evil. Yet, if the finger is not amputated then the entire hand will be lost; this is a greater evil.
Thus, the making and the creation of evil, harm, trouble, devils, and other harmful things is not evil or bad; these have been created in order to obtain many important results. For example, devils are not allowed to pester the angels and the angels can therefore not make any advance. Their ranks, although high, are fixed and can never change. Animals cannot make progress either, for the same reason; they maintain their low rank throughout their lives. On the other hand, for human beings there is no end to the ranks to which they can attain, in both directions, high or low. There are countless levels for humans to progress through, from the ranks of the Nimrods and the Pharaohs to the ranks of the saints and the prophets.
Therefore, in order to differentiate and separate those souls which are like coal in their deficiency from those that are like diamonds in being distinguished, an arena of trial, examination, strife, and competition has been established, using the creation of the devils, and the assigning of prophets, thus making humanity accountable for its actions. Were there no struggle and no competition, the coal-like and diamond-like aptitudes in mankind's disposition would have remained equal. The soul of Abu Bakr the Veracious, who was the highest of the high, would have remained level with that of Abu Jahl, the lowest of the low. As a result, the creation of the devils and evil is neither evil nor ugly as it pertains to grand and cumulative results. Evil and ugly results that arise from individual acts, and perhaps from miscalculations and abuses, should be attributed to man's acquisition, not to Divine creation.
The following question may come to mind: The majority of humanity has become disbelievers due to the existence of Satan, and hence suffer harm, despite the fact that prophets have been sent. If we judge the state of affairs according to the situation of the majority we must then conclude that the creation of evil is evil as the majority of people are suffering due its existence. We may even be drawn to the conclusion that the sending of prophets was not a blessing after all. Is this not so?
The first thing to say in answer to this question is, quantity is of no significance; we must look at quality. The true majority lies in those of quality. For example, if there are a hundred date-palm seeds that are planted, but not watered and hence they cannot undergo the necessary chemical transformations and demonstrate the struggle for life, then we only have a hundred seeds that have virtually no value. But if instead these seeds are watered and they then partake in the struggle for life, but still eighty out of the hundred rot due to the imperfections inherent in their nature, with only twenty becoming fruit-bearing trees, can we then claim that "watering the seeds was evil because most of them rotted"? Of course we cannot do so, for those twenty seeds will yield twenty thousand more seeds. Therefore, what has caused a loss of eighty and a profit of twenty thousand is not harmful and cannot be called evil.
To give another example, consider a peahen that lays a hundred eggs, each being worth five dollars. If the hen were to incubate those hundred eggs and eighty were to spoil, that would mean that twenty hatch into adults. Can we say that there was a high loss caused by a harmful process, and that therefore incubating is bad by its very nature? No, on the contrary, it is profitable, for these birds lost eighty eggs, worth five dollars each, but gained twenty peacocks worth eighty dollars.
It is in just this way that mankind, by being raised up by the prophets, and by fighting against Satan and their evil-commanding souls, have lost the animal-like members of their race, the disbelievers and hypocrites, who are greater in number but poorer in quality, in exchange for hundreds of thousands of prophets, millions of saints, and billions of men of wisdom and sincerity, who are the suns, moons, and stars of the human world.
Another question that one might want to ask, is that God Almighty sends catastrophes and inflicts us with trials and tribulations; is this not unfair, particularly toward the innocent, even the animals?
The answer to this question is, the sovereignty is His; therefore He reigns over this creation of His as He wishes. Here is a simple example in order to better understand this statement: Imagine that a skilful craftsman hires you as a model. He has you put on a beautiful garment that he has made and in order to demonstrate his skills on it he starts cutting, trimming, shortening, lengthening it and making you sit down or stand as he wishes. Can you tell him that he is making the garment that looks so beautiful on you appear ugly, or that he is tiring you out by making you move all the time? Of course not, he has hired you. Likewise your Maker, All-Glorious, has you put on this fine looking body of yours, which is ornamented with senses, such as hearing, seeing, speaking, etc., and in order to demonstrate the gilding of His various names, He sometimes makes you ill, hungry, thirsty, worried, or sometimes he satisfies you; your life revolves around different states like these. In order to strengthen the essence of life and display the manifestation of His Names, He makes you journey through numerous such conditions. If you say: "Why do you inflict these calamities on me?", there are several instances of wisdom that will silence you, as in the above analogy.
Another point is that tranquility, stillness, idleness, and monotony are forms of non-existence, and thus are not good states. Action and constant change on the other hand are signs of existence; therefore these are good states. Life finds its perfection through action and it evolves through tribulations. Life encounters various actions through the manifestations of Divine Names and so it becomes purified and fortified; this is how it evolves, expands and becomes the pen with which the determination of its own fate is written, and so deserves to be rewarded in the afterlife.