In the hour of prayer, when our mind wanders to thoughts of bad things, or if these thoughts come without our wanting them, we shouldn’t wage an offensive war against the enemy; because, even if all the lawyers in the world joined together, they wouldn’t make any headway with a little demon. Only through ignoring these thoughts can one chase them away. The same is true for blasphemous thoughts.
The Elder Paisios
I have also heard it said that filling our hearts with prayers to God, rather than chasing evil thoughts, can be effective.