Trying to achieve something, but ending up with something contrary

You can say the plans backfired or the plans are counterproductive when the effect is opposite of what is intended.


This might be called an unintended consequence

In the social sciences, unintended consequences (sometimes unanticipated consequences or unforeseen consequences) are outcomes that are not the ones intended by a purposeful action.


Just like p.s.w.g said, the word serendipity aptly describes an "accidental discovery" and is usually used in a positive sense, such as indicating success.

If you are trying to describe a situation in which something goes wrong in an unexpected fashion, then a word that comes to my mind is setback which The Free Dictionary defines as:

set·back

/ˈsetˌbak/

noun

1. An unanticipated or sudden check in progress; a change from better to worse.

For example: "A serious setback for the peace process."

Synonyms include: problem, difficulty, hitch, complication, upset, disappointment, misfortune, mishap, reversal.


Some of the suggestions here are good and apply to either positive or negative unexpected outcomes.

I thought a term that can be applied to both scenarios is situational irony