Has it ever happened that a theorem of the form
If $P$, then $Q$
was proven and published, perhaps with great difficulty, only for someone to realize later that the condition $P$ of the theorem is never satisfied, or, worse, that the conclusion $Q$ of the implication is false?
For example, if the Generalized Riemann Hypothesis were disproved tomorrow, I would have a large supply of examples on my hands, as so many results are conditional on GRH. But surely, this must have happened before, in the long history of mathematics?
In the proof of FLT, was essential the fact that nontrivial FLT solution $\implies$ $\exists$ weird elliptical curve. Wiles proved that there isn't weird elliptical curve. See A question on FLT and Taniyama Shimura.