Evil thoughts could very well be whisperings of Satan. Whenever such thoughts occur to you, you must turn your attention immediately away from them by seeking refuge in Allah and making dhikr (remembrance of Allah).
Sheikh Ahmad Kutty, a senior lecturer and Islamic scholar at the Islamic Institute of Toronto, Ontario, Canada, states: These kinds of thoughts that assail your minds are due to suggestions and whisperings of the Devil. Allah tells us in the Qur’an that the Devil is our plain enemy who is always around us waylaying us, and stealthily putting these kinds of evil thoughts in order to snatch our faith. Allah says quoting Satan, (He said, “Now, because You have sent me astray, I shall lurk in ambush for them on Your straight path. Then I shall come upon them from before them and from behind them and from their right and from their left, and You shall not find most of them thankful (for Your mercies)) (Al-A`raf 7:16-17).

Although Satan has been given some limited powers, he cannot exercise any permanent control over the true servants of Allah. Allah says: (When you recite the Qur’an, seek refuge in Allah from the accursed Devil. He has no power over those who believe and put their trust in their Lord. His Power is only over those who make an ally of him and those whom he causes to associate (other deities with Allah)) (An-Nahl 16:98-100).
The Prophet (peace and blessings be upon him) said, “Satan runs through the blood veins of son of Adam, but when he remembers Allah, Satan retreats!”
Therefore, there is no greater weapon we can wield to fight against Satan than constancy in dhikr (remembrance of Allah). That is why Allah says, (Those who fear (Allah), when a passing notion from the Devil troubles them, they remember, and they (immediately) see (clearly between right and wrong)) (Al-A`raf 7:201).
It is, therefore, imperative on us, whenever such thoughts or suggestions from the Devil assail our minds, to repel them through dhikr and seeking refuge in Allah. Here are a few protective devices and refuges that we must use on a regular basis as well as when such evil suggestions afflict us:
1. Bismillaahi alladhee Laa yahdurr ma`ismihi shay’un fi al-ardi walaa fi as-samaa’i wa huwa as-samee`u al-`aleem. (In the name of Allah; with His name, nothing whatsoever on earth or heaven can inflict any harm; He is the All-Hearing, the All-Knowing.)
2. Radheetu bi Allahi rabban, wa bi al-islaami deenan, wa bi Muhamma
din nabiyyan wa rasoolan. (I am well pleased with Allah as my Lord, Islam as my religion, and Muhammad (peace and blessings be upon him) as His Prophet and Messenger.)
3. Rabbi a`oodhu bika min hamaazaati ash-shayaateeni wa a`oodhu bika rabbi an yahdhurooni. (My Lord, I seek refuge in You from the whisperings of the devils and I seek refuge in You, my Lord, from their presence with me).
Also, as soon as such thoughts occur, say: A`oodhu billaahi mina ash-shaytaani ar-rajeem. (I seek refuge in Allah from Satan, the accursed.)

And make istighfar (seeking forgiveness of Allah) saying: Astaghfiru Allaaha al-`azheem min kulli dhanbin wa atoobu ilayhi. (I seek refuge in Allah, the Tremendous, from all of my sins, and I repent to Him.)
Eventually, by arming yourself with the weapon of dhikr and ikhlas (sincerity in worship of Allah), you will find yourself empowered over Satan. May Allah grant us victory in our struggle against the Evil One; may He bless us with the honor of dying on tawheed. Ameen.