There’s even a pointwise version of the result. I denote the topology of a space $X$ by $\tau(X)$.
For $y\in N$ let
$\begin{align*} \mathscr{N}(y)&=\{U\in\tau(N):y\in U\},\\ \mathscr{B}_y&=\{f^{-1}[U]:y\in U\in\tau(N)\},\text{ and}\\ \mathscr{V}_y&=\{V\in\tau(M):f^{-1}[\{y\}]\subseteq V\}\;, \end{align*}$
and let $\mathscr{F}_y$ be the filter on $M$ generated by $\mathscr{B}_y$; the claim is that $f$ is closed iff for each $y\in N$, $\mathscr{V}_y\subseteq\mathscr{F}_y$.
Definition: The function $f$ is closed at $y\in N$ iff for each closed $K\subseteq M$, $y\in\operatorname{cl}f[K]$ iff $y\in f[K]$.
Proposition: Let $y\in N$; then $f$ is closed at $y$ iff $\mathscr{V}_y\subseteq\mathscr{F}_y$.
Proof: Suppose that $\mathscr{V}_y\nsubseteq\mathscr{F}_y$, and fix $V\in\mathscr{V}_y\setminus\mathscr{F}_y$. Let $K=M\setminus V$; $K$ is closed, and $K\cap f^{-1}[\{y\}]=\varnothing$, so $y\notin f[K]$. Since $V\notin\mathscr{F}_y$, for each $U\in\mathscr{N}(y)$ there is a point $x_U\in f^{-1}[U]\setminus V=K\cap f^{-1}[U]$; clearly $f(x_U)\in U\cap f[K]$, so $y\in\operatorname{cl}f[K]$, and therefore $f[K]$ is not closed.
Conversely, suppose that $y\in\operatorname{cl}f[K]\setminus f[K]$ for some closed $K\subseteq M$. Let $V=M\setminus K$; clearly $V\in\mathscr{V}_y$. Suppose that $U\in\mathscr{N}(y)$; $y\in\operatorname{cl}f[K]$, so $U\cap f[K]\ne\varnothing$, and therefore $f^{-1}[U]\setminus V=f^{-1}[U]\cap K\ne\varnothing\;.$ Thus, $V\notin\mathscr{F}_y$, and hence $\mathscr{V}_y\nsubseteq\mathscr{F}_y$. $\dashv$