[proofplan]
We prove the criterion by testing continuity on open sets in the [cofinite topology](/page/Cofinite%20Topology). First, if $f$ is continuous and $F\subset Y$ is finite, then $Y\setminus F$ is open in the cofinite topology, so its preimage is open in $X$, and hence $f^{-1}(F)$ is closed. Conversely, if preimages of finite subsets of $Y$ are closed, then every cofinite open subset of $Y$ has open preimage, while the empty [open set](/page/Open%20Set) also has open preimage; this proves continuity.
[/proofplan]
[step:Pull back finite closed subsets from continuity]
Assume that $f:X\to Y$ is continuous. Let $F\subset Y$ be a finite subset. Since $Y$ has the cofinite topology, the set $Y\setminus F$ is open in $Y$. By continuity of $f$, the preimage $f^{-1}(Y\setminus F)$ is open in $X$.
The preimage operation commutes with complements relative to the domain and codomain of $f$, so $f^{-1}(Y\setminus F)=X\setminus f^{-1}(F)$. Thus $X\setminus f^{-1}(F)$ is open in $X$, which means that $f^{-1}(F)$ is closed in $(X,\tau)$. Since $F\subset Y$ was an arbitrary finite subset, the required condition holds.
[guided]
Assume that $f:X\to Y$ is continuous. We must prove that every finite subset of the codomain has closed preimage. Let $F\subset Y$ be finite.
The cofinite topology on $Y$ is defined so that a subset $U\subset Y$ is open exactly when either $U=\varnothing$ or $Y\setminus U$ is finite. Applying this to the subset $Y\setminus F$, its complement in $Y$ is $Y\setminus (Y\setminus F)=F$. Since $F$ is finite, the set $Y\setminus F$ is open in the cofinite topology on $Y$.
Now use continuity in its open-set form: because $f$ is continuous and $Y\setminus F$ is open in $Y$, the preimage $f^{-1}(Y\setminus F)$ is open in $X$. The relevant set identity is the [complement rule](/theorems/4970) for preimages: $f^{-1}(Y\setminus F)=X\setminus f^{-1}(F)$. Therefore the complement of $f^{-1}(F)$ in $X$ is open. By the definition of closed subset in the [topological space](/page/Topological%20Space) $(X,\tau)$, this says exactly that $f^{-1}(F)$ is closed in $X$. Since no special property of $F$ was used beyond finiteness, this proves the condition for every finite subset $F\subset Y$.
[/guided]
[/step]
[step:Use finite preimages to test every cofinite open subset]
Conversely, assume that for every finite subset $F\subset Y$, the set $f^{-1}(F)$ is closed in $(X,\tau)$. We prove that $f$ is continuous by showing that the preimage of every open subset of $Y$ is open in $X$.
Let $U\subset Y$ be open in the cofinite topology. If $U=\varnothing$, then
\begin{align*}
f^{-1}(U)=f^{-1}(\varnothing)=\varnothing,
\end{align*}
which is open in $X$.
If $U\neq\varnothing$, then the definition of the cofinite topology gives that $Y\setminus U$ is finite. Define $F:=Y\setminus U$. By the assumption, $f^{-1}(F)$ is closed in $X$. Again using the complement rule for preimages, $f^{-1}(U)=f^{-1}(Y\setminus F)=X\setminus f^{-1}(F)$. Since $f^{-1}(F)$ is closed, its complement $X\setminus f^{-1}(F)$ is open. Hence $f^{-1}(U)$ is open in $X$.
Thus the preimage of every open subset $U\subset Y$ is open in $X$, so $f:X\to Y$ is continuous.
[/step]