Also, I think Fermat did really think that his proof was correct (he wrote down some correct theorems in the margin, again without proof, and IIRC some whose proofs looked doable in Fermat's time). Considering that Dedekind domains weren't properly formalized until much later, he probably used unique factorization into irreducibles, which of course fails for general number fields.