How did Andrew Wiles succeed in proving Fermat's last theorem when others had failed?
A facetious, provocative answer with a shred of truth: he did not.
Andrew Wiles didn't actually prove Fermat's Last Theorem. Not directly. He proved a much deeper and more important result, the Modularity Theorem for Elliptic Curves (not all of it, but a huge and sufficiently big chunk).
The guy who proved that FLT follows from the Modularity conjecture was Ken Ribet, building on work by Serre following the original ideas of Frey and Hellegouarch. But this happened chronologically earlier, so the credit for providing the final ingredient goes, justifiably, to Wiles.
In a way, the question should be: how did Frey and Hellegouarch succeed in devising a new attack on FLT while others did not? Because really, the FLT-specific ingredient of this chain of events is theirs. The subsequent work (Serre, Ribet, Wiles) was much more broad and general, and was inspired and motivated by the original discovery that FLT, which seems to have nothing to do with elliptic curves and modular forms, can nevertheless be approached with these tools.
So how did Frey and Hellegouarch manage to do this while others before them did not? First of all, let's not take away from the fact that their (independent) ideas were a fantastic spark of genius. But this spark doesn't exist in a vacuum.
Mathematicians of the 18th and 19th and early 20th centuries couldn't possibly have devised this idea because the world wasn't ready: Frey and Hellegouarch lived at a time where we already knew a great deal about elliptic curves and their relationship with both number theory and automorphic forms. It still took genius, but this genius had a substrate to spring from. The Modularity conjecture was in the air. We knew that elliptic curves can't just do whatever the hell they want. Frey could dream up an elliptic curve from a purported solution of FLT and intuitively see that it must have weird properties, even though he couldn't prove that it truly can't be modular.
Ribet did that. Why did Ribet succeed where others have not? Well, before Frey nobody was really motivated to prove that, and then Serre formulated the precise general conjecture that would imply that Frey's curve can't be modular, and few people in the world were better prepared to solve that conjecture than Ken Ribet. Once again, let's not diminish the fact that his achievement was pure genius (it was he, actually, who proved FLT! If the Modularity conjecture was already solved, that honor would fall to him). But Ribet's breakthrough didn't exist in a vacuum either. It was impossible for anyone to do what he did years or decades earlier; the foundations weren't there.
Ribet's work left the Modularity conjecture to be solved. Wiles succeeded in doing that, together with Richard Taylor who helped him complete a crucial part. Why he? Because once again, he was uniquely positioned to. He already did profound work in this direction earlier in his career, and few people in the world knew more than he did about these concepts and ideas.
But once again, this doesn't take away from the fact that his success required both enormous tenacity and tremendous ingenuity. He had a great starting position: the world's collective progress in the relevant theories, his own deep researches into them, and the huge motivation boost he got from Ribet's work. But even given all those existing conditions, his achievement is one of the most singular breakthroughs in the history of mathematics. He's just that good.