The four sums being equal yields four linear equations; for the grid
$$\begin{matrix}a&b&c\\d&5&e\\f&g&h\end{matrix},$$
with $\{a,b,c,d,e,f,g,h\}=\{1,2,3,4,6,7,8,9\}$ you get the equations
\begin{eqnarray*}
a+b+d+5&=&x,\\
b+c+5+e&=&x,\\
d+5+f+g&=&x,\\
5+e+g+h&=&x.
\end{eqnarray*}
First note that $a+b+c+d+e+f+g+h=40$. Summing the first and fourth equations above, as well as the second and third, then shows that
$$2x=a+b+d+e+g+h+10=(40-c-f)+10=50-c-f,$$
$$2x=b+c+d+e+f+g+10=(40-a-h)+10=50-a-h,$$
so opposite corners are congruent mod $2$, i.e. each opposite pair is either both even or both odd.
Summing all four squares together yields the sum
$$4x=a+c+f+h+2(b+d+e+g)+20=60+b+d+e+g,$$
which in turn shows that
$$b+d+e+g\equiv0\pmod{4},$$
and because $a+b+c+d+e+f+g+h=40$ also
$$a+c+f+h\equiv0\pmod{4}.$$
The latter shows that the corners are either all even or all odd. From here, let's simply see how far this restricts the square.
If $a$, $c$, $f$ and $h$ are all even, then $b$, $d$, $e$ and $g$ are all odd. Rotating and reflecting the square if necessary we get $b<d,e,g$ and $d<e$. Because $\{b,d,e,g\}=\{1,3,7,9\}$ we have
$$\begin{matrix}a&1&c\\3&5&7\\f&9&h\end{matrix}
\qquad\text{ or }\qquad
\begin{matrix}a&1&c\\3&5&9\\f&7&h\end{matrix}
\qquad\text{ or }\qquad
\begin{matrix}a&1&c\\7&5&9\\f&3&h\end{matrix}.$$
In the first two cases, from the top left square and the bottom right square we have
$$a+1+3+5=5+7+9+h,$$
and so $a=h+12$, which is of course impossible. For the latter case we have
$$1+c+5+9=x=7+5+f+3,$$
and so $c=f$, a contradiction.
Hence $a$, $c$, $f$ and $h$ must be all odd. Then $b$, $d$, $e$ and $g$ are all even, and again after rotating and reflecting if necessary, we have one of
$$\begin{matrix}a&2&c\\4&5&6\\f&8&h\end{matrix}
\qquad\text{ or }\qquad
\begin{matrix}a&2&c\\4&5&8\\f&6&h\end{matrix}
\qquad\text{ or }\qquad
\begin{matrix}a&2&c\\6&5&8\\f&4&h\end{matrix}.$$
In the latter two cases, comparing the top right square and the bottom left square shows that
$$2+c+5+8=4+5+f+6,$$
and hence that $c=f$, a contradiction. Then we are left only with the first case, and comparing the top left square and the bottom right square shows that
$$a+2+4+5=5+6+8+h,$$
and so $a=h+8$. Then $a=1$ and $h=9$, and it quickly follows that $c=7$ and $f=3$, yielding
$$\begin{matrix}9&2&7\\4&5&6\\3&8&1\end{matrix}$$