While Nick R assumes in his answer that from Boyer's writing the formula is due to De Moivre, I think that is misleading and the first derivation of the formula you ask about really should be credited to Laplace.
De Moivre was working on the binomial approximation to the normal distribution, and his approximation involved a constant $B$ (I am taking that notation from De Moivre's paper at the York University site that Nick R links to in his answer). De Moivre could express $B$ as a series but he was not able to express $B$ in closed form. Stirling told him that $B = \sqrt{2\pi}$, without proof, and with this clue De Moivre was later able to derive that nice formula for $B$ using the Wallis product for $\pi$. The key point I want to make is that in none of this work (from the 1720s) was De Moivre directly using anything like an integral of $e^{-x^2}$ in order to make any calculations.
A better paper to look at on the York University website is here.
The first proof of the integral formula you ask about where the author used integrals was given by Laplace in the 1770s. He wrote the formula (after the change of variables $y = e^{-x^2}$) as
$$
\int_0^1 \frac{dy}{\sqrt{-\log y}}\,dy = \sqrt{\pi}
$$
and derived this from a formula for integrals due to Euler.
See here for many proofs of the integral formula you ask about. The eighth proof is Laplace's argument I allude to above and explains how it uses a result of Euler, and the tenth proof shows that this formula is equivalent to identifying the constant in Stirling's asymptotic estimate for $n!$ as $\sqrt{2\pi}$. The second proof is a much nicer alternate proof by Laplace that is a forerunner of the standard proof via squaring the integral and passing to polar coordinates; Laplace's alternate argument squares the integral and makes a different change of variables.
See the end of this for a discussion of how De Moivre's work on the binomial approximation to the normal distribution intersected with Stirling's work on Stirling's formula, and how Stirling found the constant $\sqrt{2\pi}$ in his formula.