Fermat's last theorem was originally not so much a theorem as a conjecture. Pierre de Fermat was a 17th Century French lawyer who spent his spare time thinking about number theory1. He made a note in his copy of Bachet's translation of Diophantos' Arithmetica, next to the posed problem of finding all solutions to the equation in Pythagoras theorem. It seemed to him that the generalised problem of finding integer solutions a, b, c to the equation an+bn = cn was impossible, provided that n is an integer larger than two; and that he had found a demonstrationem mirabilem - 'a marvellous proof' - but that hanc marginis exiguitas non caperet, 'this margin was not able to contain it'.
This claim spurred the minds of several major mathematicians - Pierre's elder son published the translation of Bachet together with his father's comments - and most of the great brains of that time set out to work on the problem of proving that such a triplet a, b, c cannot possibly exist. The problem is quite easily and obviously reduced to that of testing prime exponents; that is, cases of the equation where n is a prime number (a number which can only be divided by 1 or itself without residue). Euler, Lebesgue, and several others proved the theorem for special cases - usually just one or two prime exponents at the time.
With Sophie Germain, progress was made at a slightly faster rate - she proved the theorem for two infinite sets of primes - the Germain primes (ie, primes such that if p is prime, then 2p+1 is prime too - or 4p+1. The numbers 2, 3 and 5 are examples of Germain primes). Together with Lebesgue, she was able to prove the theorem for a total of ten of these classes. This was the first time anyone had proven Fermat's Last Theorem for an infinite number of cases. Not bad for a cloth-trader's daughter who was not even allowed to study mathematics since it would damage her femininity.
Some years later, the German mathematician Kummer proved the theorem for all regular primes - ie, all primes that divide the numerator of a so-called Bernoulli number. Bernoulli numbers occur as the coefficients when you evaluate the function x/(ex-1) as a polynomial.
After this, not much happened for a while, until a spoiled rich kid named Wolfskehl came on the scene. His interest in Fermat's Last Theorem was aroused when one evening he failed to commit suicide due to reading about the theorem (he started thinking about suicide because the girl he loved married another). He committed everything he owned to a prize that was to be awarded to the first person to prove Fermat's Last Theorem. A counter-example wouldn't win the prize - only positive proof would.
After the Wolfskehl prize was announced, amateur mathematicians started pouring in incorrect proofs to mathematical institutions all over the world; and very soon work on Fermat's Last Theorem was no longer seen as appropriate in the mathematical community.
With the advent of computers, researchers were able to test different cases and, rather soon, all possible cases up to numbers ranging over absurdly high figures (10999999 and stuff like that) were tested - but still no full proof.
In 1985, the German researcher Gerhard Frey suggested that the Shimura-Taniyama conjecture dealing with relations between elliptic curves and modular forms (essentially stating that they are the same) implies Fermat's Last Theorem - since if a solution would be found, an elliptic curve could be constructed, that would contradict Shimura-Taniyama. Thus, if Shimura-Taniyama could be proven right, then any solution to the equation in Fermat's Last Theorem would automatically be non-existent.
Elliptic Curves originated from the study of the length of the arc of an ellipse. Trying to work this out led to integrals that the mathematicians of the time were unable to evaluate, whereupon they did as most mathematicians do when they chance upon some obstacle; they invented functions that were defined by the fact that they solved these particular integrals2. These solutions were called elliptic functions and they turned out to have specific properties: for example, being able to to map them onto the plane in such a way that the values of the function and of its derivative plotted a curve with the equation y2=x3+ax+b. There is a splendid online tutorial where you can fiddle around with elliptic curves and see what they look like.
A modular form is a function over the complex numbers3 that satisfies certain conditions. Basically, in the same way that sine waves repeat themselves after a while along the line, modular forms repeat themselves in two different directions; the value of the function at one point is the same as the value a short bit to the right or another short bit upwards from the point.
Shimura and Taniyama
The two Japanese mathematicians Shimura and Taniyama started suspecting certain things during the 1950s. They could generate a so-called L-series from certain modular forms, and match them with L-series from certain elliptic curves. They stipulated that this had some significance, and even that this would be possible with every single elliptic curve (and every single modular form). In the beginning they were laughed at, but by and by, more and more mathematics began to build on the assumption that they did, in fact, guess correctly.
Then Gerhard Frey threw out the idea, that given a solution A, B, C to the equation an+bn=cn, then the elliptic curve y2=x(x-An)(x+Bn) could be formed. This curve would, among other things, have the property that the so-called discriminant would include an expression (AB)n, where n would have to be a very large number (remember that the theorem had been proven true up to ridiculously high exponents), and thus that any divisor of AB would occur ridiculously many times; something that did - in essence - make the whole curve quite fantastic.
So fantastic in fact, that Ribet managed to prove, that if this curve existed, then it would necessarily contradict the guess that Shimura and Taniyama made; thus if Shimura and Taniyama could be proven right, then this curve could not exist, and then the solution could not exist, and therefore Fermat would be correct in his claim that no such solution can possibly exist.
This the British mathematician Andrew Wiles managed to prove, after some seven years of intense work, in 1993, followed by a correction of his (then slightly erroneous) proof in 1995. Most probably, Fermat came up with a slightly flawed proof; something which his own correspondence indicates (as he grew older, he stopped referring to the full problem, and only challenged the mathematicians he wrote to with specific exponents). Most definitely, he did not come up with Wiles' proof, as that stretched over some 250 pages (including the correction) and used techniques developed during the latter part of the 20th Century.