I will discuss a general case of which your demeaning is a special case where $X_2$ is just the constant term, see Utility of the Frisch-Waugh theorem.
The Frisch Waugh Lovell theorem tells us that the coefficient $\hat\beta_1$ on the variables $X_1$ of a regression of $y$ on $X_1$ and $X_2$ can
(a) be obtained as usual by regressing $y$ on both $X_1$ and $X_2$ or
(b) by first regressing both, in separate regressions, $y$ and $X_1$ on $X_2$, saving the residuals of these regressions. These can, using the "residual maker matrix" $M_{X_2}=I-X_2(X_2'X_2)^{-1}X_2'$, be written as $M_{X_2}y$ and $M_{X_2}X_1$. Then, regress these residuals of the regression of $y$, $M_{X_2}y$, on those for the regressions for $X_1$, $M_{X_2}X_1$, or
(c) by only regressing $X_1$ on $X_2$, saving the residuals of these regressions and regress $y$ on the residuals for the regressions for $X_1$
Now, (b) can be written as, using the standard OLS formula,
$$
\hat{\beta}_{\text{ols},1}=(X_1'M_{X_2}'M_{X_2}X_1)^{-1}X_1'M_{X_2}'M_{X_2}y
$$
(to see this, just apply the general OLS expression $(X'X)^{-1}X'y$ to $X=M_{X_2}X_1$ and $y=M_{X_2}y$).
I skip that this is the same as (a), cf. e.g. Frisch-Waugh-Lovell theorem.
Why is the same as (c)?
Notice that $M_{X_2}$ is symmetric and idempotent (i.e., $M_{X_2}'M_{X_2}=M_{X_2}M_{X_2}=M_{X_2}$), so that we may as well write
$$
\hat{\beta}_{\text{ols},1}=(X_1'M_{X_2}'M_{X_2}X_1)^{-1}X_1'M_{X_2}'y
$$
(or $(X_1'M_{X_2}X_1)^{-1}X_1'M_{X_2}y$, if we wish), which is (c). This is what your regression of $y$ on demeaned $x$ amounts to.
It is (unless $M_{X_2}X_1=X_1\Leftrightarrow X_1'X_2=0$, i.e. unless regressors are orthogonal - in your case, unless $x$ has sample mean zero) however not the same as writing
$$
(X_1'X_1)^{-1}X_1'M_{X_2}y.
$$
This is what your regression of demeaned $y$ on $x$ amounts to.