Surjectivity of the induced map of affine algebraic sets For a morphism $f: X\rightarrow Y$ of affine algebraic sets, I want to show that if the induced map $f^*:k[Y]\rightarrow k[X]$ is surjective then $f(X)$ is closed.

I am trying to prove that $f(X)=Z(\ker f^*)$. The direction $f(X)\subset Z(\ker f^*)$ is easy but I am stuck for the other one.

I know it was asked before (Why does surjectivity of the induced map show that a morphism of affine varieties has closed image?) but the solution offered showed that $f$ surjective implied $f^*$ has a closed image.

Thanks!
Let  $X \subset k^m$.  For every $1 \le i \le m$ there exist  $g_i$ in $k[Y]$ so that for the coordinate function $x_i$ in $k[X]$ we have

$$x_i = g_i(f(x))$$
We get a map $g \colon Y \to k^m$ such that 
$$x = g(f(x))$$ for all $x \in X$. ($\tiny{ \text{ We got the inverse map, just a bit more work needed.} }$)

Let $Z$ the Zariski closure of $\phi(X)$ in $Y$. Let's show first that 
$$g(Z) \subset X$$ 
Indeed, let $p_{\alpha}(x)=0$ equations giving $X$. Want to show that $p_{\alpha}(g(z))= 0$ for all $z \in Z$. Now $p_{\alpha}(g(f(x))= p_{\alpha}(x) = 0$ for all $x \in X$. Since $Z$ is the Zariski closure of $f(X)$ we conclude that $p_{\alpha}(g(z)) = 0$ for all $z \in Z$. 

We have maps 
$$f \colon X \to Z\\
g \colon Z \to X$$ 

and $$\mathbb{1}_X = g \circ f$$ Let's show that $$f\circ g = \mathbb{1}_Z$$ It's enough to show the equality on the dense subset $f(X)\subset Z$. We have

$$f\circ g( f(x) = f(g(f(x)) = f(x)$$

So $g$ is the inverse map of $f$, and therefore $f(X) = Z$ is closed. Moreover, the map $f\colon X \to f(X)$ is an isomorphism.

$\tiny{ \text{The proof works in other categories (analytic, smooth).}}$
Here is a proof of the other inclusion wich does not take the detour via affine schemes:

Because of the inclusion already shown, we can switch the codomain from $Y$ to $Z(\operatorname{ker}(f^*))$. This corresponds to taking the quotient of $k[Y]$ by $\operatorname{ker}(f^*)$. This quotient is isomorphic to $k[X]$ by the homomorphism theorem because $f^*$ is surjective. But then this implies that $X$ and $Z(\operatorname{ker}(f^*))$ are isomorphic via $f$. In particular $f(X)=Z(\operatorname{ker}(f^*))$.

what we are using here is the equivalence between algebraic sets and reduced finitely generated k-algebras. I hope I didn't mix up the order in which things are usually shown here.