The injunction from the book of Allāh in regards to repelling evil deeds with good deeds.
I also advise you with five matters: when you are treated unjustly, do not behave unjustly; when you are praised, do not become happy; when you are criticized, do not become upset; when you are not believed, do not become angry; and if people act deceitfully towards you, do not act deceitfully towards them.
Allāh the Exalted said:
“The good deed and the evil deed cannot be equal. Repel evil with that which is better; then indeed, he between whom and you there was enmity, will become as though he was a close friend.”
[Sūrah al-Fuṣṣilat 41:34]
Imām al-Saʿdī (d.1376H) – raḥimahullāh – said:
“Not equal are acts of goodness and obedience, which are done to earn the pleasure of Allāh; and acts of evil and disobedience, that bring about the anger of Allāh, and not His good pleasure. Likewise, not equal are those acts of goodness and kindness that are done towards the creation, and those acts of evil done against them - neither in their nature, their characteristics, nor in their rewards: “Is not the reward for good acts, goodness.” Then, a particular, but important act of iḥsān (goodness and kindness) is commanded, which is: showing iḥsān towards the one who has ill-treated you; because Allāh commanded to repel evil with that which is better. This means that whenever you are ill-treated by anyone from amongst the creation - in particular those that have great rights over you; such as relatives, friends, and their like - then return their ill-treatment of you with acts of kindness and goodness towards them. Thus, if you have been cut-off from then seek to join the ties of relation; if you have been oppressed, then be forgiving; if you have been spoken ill of, either in your presence or behind your back, then do not retaliate, but rather be forgiving and speak to them with mild and soft words; if you have been boycotted and abandoned, then continue speaking to those who have done so, with good words, and continue giving them the greetings of salām. So if you return acts of evil with acts of iḥsān (goodness and kindness), then you will indeed acquire a tremendous benefit.” 
Consider also, the following incident:
’Aa‘ishah (raḍī Allāhu ’anhaa) said:
I asked the Prophet (ṣallallāhu ʿalayhi wa-sallam): O Allāh’s Messenger, has there ever been a day more severe upon you than the day of Uhud? So he said: “Your tribe troubled me greatly, and the most troublesome thing which I experienced from them was on the day of ’Aqabah when I presented myself to Ibn ’Abd-Yaaleel Ibn ’Abd-Kulāl, and he did not respond to my Message as I had hoped. So I returned overwhelmed with grief and sorrow, and did not recover until I reached Qarnuth-Tha’aalib. I raised my head and saw a cloud shading me. Then I looked and saw (the Angel) Jibrīl in it, and he called me saying. Allāh has heard what your people have said to you, and their reply. And Allāh has sent the Angel of the mountains to you to do whatever you wish. So the Angel of the mountains called me, greeted me with Salām; and then said. O Muḥammad. Allāh has heard what your people said to you, and I am the Angel of the mountains. My Lord has sent me to you, that you may order me as you wish. So what do you wish? If you should so wish, I will crush them beneath the two mountains.” So Allāh’s Messenger (ṣallallāhu ʿalayhi wa-sallam) said: “No, rather hope that from their offspring will come who will worship Allāh alone, and not worship anything else along with Him.” 
Ibn Abī Ḥātim (d.328H) - raḥimahullāh - said:
“I entered Damascus and came upon the students of ḥadīth, and I passed by the circle of Qaasim al-Joo’ee (d.248H). I found a group sitting around him and he was speaking. Their appearance amazed me; and I heard him saying: “Seize the benefit of five things from the people of your time: when you are present, you are not known; when you are absent, you are not missed; when you are seen, your advice is not sought; when you say something, your saying is not accepted; and when you have some knowledge, you are not given anything for it. I also advise you with five matters: when you are treated unjustly, do not behave unjustly; when you are praised, do not become happy; when you are criticised, do not become upset; when you are not believed, do not become angry; and if people act deceitfully towards you, do not act deceitfully towards them.” Ibn Abī Ḥātim said: So I took that as my benefit from Damascus.” 
 Tayseerul-Kareemir-Raḥmān (p. 695)
 Related by al-Bukhārī (no. 3231) and Muslim (no. 1795)
 Related by Ibn al-Jawzī in Ṣifat-Safwah (2/200)