Allah T'ala says in the Holy Quran:
وَلَا تَسْتَوِي الْحَسَنَةُ وَلَا السَّيِّئَةُ ادْفَعْ بِالَّتِي هِيَ أَحْسَنُ فَإِذَا الَّذِي بَيْنَكَ وَبَيْنَهُ عَدَاوَةٌ كَأَنَّهُ وَلِيٌّ حَمِيمٌ
(41:34) (O Prophet), good and evil are not equal. Repel (evil) with that which is good, and you will see that he, between whom and you there was enmity, shall become as if he were a bosom friend (of yours).
To understand the full significance of these words, one should keep in view the conditions in which the Holy Prophet and, through him, his followers were given this instruction. The conditions were that the invitation to the Truth was being resisted and opposed with extreme stubbornness and severe antagonism, in which all bounds of morality, humanity and decency were being transgressed. Every sort of lie was being uttered against the Holy Prophet and his Companions; every kind of evil device was being employed to defame him and to create suspicions against him in the minds of the people; every kind of accusation was being levelled against him and a host of the propagandists were busy creating doubts against him in the hearts; in short, he and his Companions were being persecuted in every possible way because of which a substantial number of the Muslims had been compelled to emigrate from the country. Then the program that had been prepared to stop him from preaching was that a handful of mischievous people was set behind him, who would raise such a hue and cry that no one could hear anything as soon as he opened his mouth to preach his message. In such discouraging conditions when apparently every way of extending invitation to Islam seemed blocked, the Holy Prophet was taught this recipe for breaking the opposition.
First, it was said that goodness and evil are not equal, as if to say: "Although apparently your opponents might have raised a dreadful storm of mischief and evil, as against which goodness might seem absolutely helpless and powerless, yet evil in itself has a weakness which ultimately causes its own destruction. For as long as man is man, his nature cannot help hating evil. Not only the companions of evil, even its own upholders know in their hearts that they are liars and wicked and are being stubborn for selfish motives. Not to speak of creating dignity and honor for them in the hearts of others, it lowers them in their own esteem, and causes their morale to be weakened and destroyed in the event of every conflict. As against this evil, the good which appears to be utterly helpless and powerless, goes on operating and working and it becomes dominant in the long run. For, in the first place, the good has a power of its own which wins the hearts and no man however perverted and corrupted, can help esteeming it in his own heart. Then, when the good and evil are engaged in a face to face conflict and their nature and merits become apparent and known, after a long drawn out struggle, not many people would be left, who would not start hating the evil and admiring the good.
Second, it was said that evil should be resisted not by the mere good but by a superior good, as if to say: "If a person treats you unjustly and you forgive him, it is the mere good. The superior good is that you treat the one who ill-treats you with kindness and love." The result would be that "your worst enemy would become your closest friend," for that is human nature itself. If you remain quiet in response to an abuse, it will be mere goodness but it will not silence the abuser. But if you express good wishes for him in response to his abuses, even the most shameless opponent will feel ashamed, and then would hardly ever be able to employ invectives against you. If a person doesn't miss any opportunity to harm you, and you go on tolerating his excesses, it may well make him even bolder in his mischiefs. But if on an occasion he gets into trouble and you come to his rescue, he will fall down at your feet, for no mischief can hold out against goodness.
However, it would be wrong to take this general principle in the meaning that every enemy will necessarily become a close friend when you have treated him with the superior good. There are such wicked people also in the world, whose inimical nature will never change for the better no matter how tolerantly you may overlook their excesses and how benevolently you may react and respond to every evil committed by them.