Here's my approach: suppose $f: X \to Y$ is morphism of varieties, and assume additionally that $X$ is Noetherian (i.e. admits a finite cover with affine varieties). Then $f$ is quasicompact and quasiseparated, so $f_* \mathcal{O}_X$ is a quasicoherent $\mathcal{O}_Y$ module, and $f$ induces a map of quasicoherent $\mathcal{O}_Y$ modules $\mathcal{O}_Y \to f_* \mathcal{O}_X$, and let $\mathcal{F}$ be the (quasicoherent) cokernel.
Consider any closed $y = f(x)$ in $Y$. Then, we have induced map $\mathcal{O}_{Y,f(x)} \to (f_* \mathcal{O}_X)_{f(x)} \simeq \mathcal{O}_{X,x}$. Since by assumption it's surjective, the stalk of the cokernel $\mathcal{F}_{f(x)}$ is zero, thus $\mathcal{F}|_V = 0$ for some neighbourhood of $f(x)$. Since closed points are dense in $X$, and $f$ is closed immersion, they're also dense in the image $f(X)$, so the cokernel $\mathcal{F}$ is zero in some open neighbourhood of $f(X)$. Outside of $f(X)$ it's trivially 0, as $(f_* \mathcal{O}_X)_y = 0$ for $y$ outside $f(X)$ (since $f(X)$ is closed). We conclude that $\mathcal{F} = 0$, and so $\mathcal{O}_Y \to f_* \mathcal{O}_X$ is epimorphism of sheaves.
Now, if we could prove that $f$ is affine morphism, it would remain to prove that for any affine $\mathrm{Spec} A \subset Y$, $\mathcal{O}_Y(\mathrm{Spec} A) \to f_* \mathcal{O}_X(\mathrm{Spec} A)$ is a surjective ring map, but this is obvious since $\mathcal{O}_X$ and $f_* \mathcal{O}_Y$ are quasicoherent, and $\mathcal{O}_Y \to f_* \mathcal{O}_X$ is surjective.
Does $f$ need to be affine, though? I don't know.