‘Yes, there can be no doubt,“ said Aragorn. ‘At last we know the link between Isengard and Mordor, and how it worked. Much is explained.’
‘Strange powers have our enemies, and strange weaknesses!’ said Théoden. ‘But it has long been said: oft evil will shall evil mar.’
‘That many times is seen,’ said Gandalf. ‘But at this time we have been strangely fortunate. Maybe, I have been saved by this hobbit from a grave blunder. […] ’
―J R R Tolkien, The Lord of the Rings, Book 3, Chapter XI: ‘The Palantír’
The formulation of this phrase seems odd and I can’t pick the full meaning out of it. He says it after Wormtongue (Gríma) has thrown the palantír out of the tower of Orthanc, which seems to be a great example of evil shooting itself in its own foot, but that doesn’t seem to be the thrust of the phrase.