Assume that $A^TA$ is invertible. Then consider the matrix $M=A\left(A^TA\right)^{-1}A^T$. It is not hard to verify that
$$
M^2=M\tag{1}
$$
and
$$
M^T=M\tag{2}
$$
$(1)$ and $(2)$ show that $M$ is an orthogonal projection onto the column space of $A$. To see that it is onto the column space of $A$, note that $MA=A$. It is orthogonal because for any $x,y$
$$
\begin{align}
\langle Ax,My-y\rangle
&=\langle Ax,My\rangle-\langle Ax,y\rangle\\
&=\langle M^TAx,y\rangle-\langle Ax,y\rangle\\
&=\langle MAx,y\rangle-\langle Ax,y\rangle\\
&=\langle Ax,y\rangle-\langle Ax,y\rangle\\
&=0\tag{3}
\end{align}
$$
Since $Mb$ is the orthogonal projection of $b$ onto the column space of $A$, it should be the closest point to $b$ of any $Ax$. Therefore, let
$$
r=\left(A^TA\right)^{-1}A^Tb\tag{4}
$$
which is equivalent to the condition $A^TAr=A^Tb$.
$Ar=Mb$ should be the closest point to $b$ of any $Ax$. In fact, if we use $(4)$ and apply $(3)$, we have
$$
\begin{align}
\|A(r+x)-b\|^2
&=\langle Mb+Ax-b,Mb+Ax-b\rangle\\
&=\|Mb-b\|^2+2\langle Ax,Mb-b\rangle+\|Ax\|^2\\
&=\|Ar-b\|^2+\|Ax\|^2\tag{5}
\end{align}
$$
Thus, $(5)$ shows that $\|A(r+x)-b\|^2$ is minimal iff $Ax=0$ and since $A^TA$ is invertible, $Ax=0\iff x=0$. Therefore, $(4)$ does give the least squares solution as implied by the orthogonality.
Another Approach
Consider
$$
\begin{align}
\|A(r+x)-b\|^2
&=\langle Ar+Ax-b,Ar+Ax-b\rangle\\
&=\langle Ar-b,Ar-b\rangle+2\langle Ar-b,Ax\rangle+\langle Ax,Ax\rangle\\
&=\|Ar-b\|^2+2\langle A^TAr-A^Tb,x\rangle+\|Ax\|^2\tag{6}
\end{align}
$$
Let $x=t(A^TAr-A^Tb)$, then $(6)$ says
$$
\|A(r+x)-b\|^2=\|Ar-b\|^2+2t\|A^TAr-A^Tb\|^2+t^2\|AA^TAr-AA^Tb\|^2\tag{7}
$$
For $\|Ar-b\|^2$ to be a minimum, the derivative of $(7)$ must equal $0$. That is, $\|A^TAr-A^Tb\|^2=0$
Therefore, for $\|Ar-b\|^2$ to be a minimum, we must have
$$
A^TAr-A^Tb=0\tag{8}
$$