Your factorisation was incorrect. It only works for reals!
We can see the fallacy if we extend it a little:
\sqrt{x^2-a^2} & = \sqrt{-1(a^2-x^2)} \\ & = \sqrt{-1}\sqrt{a^2-x^2} $ this is what you've done $ \\ & = i\sqrt{a^2-x^2} \\ & = i\sqrt{-1(x^2-a^2)} \\ & = i\cdot i \sqrt{x^2-a^2} \\...