Yes, the statement is true, indeed a stronger statement is:
Theorem: Let $X,Y$ be Hausdorff spaces and let $f\colon X\to Y$ be a continuous closed surjection such that $f^{-1}(y)$ is compact for every $y\in Y$. Then $f$ is proper, meaning that if $Z\subseteq Y$ is compact, then $f^{-1}(Z)$ is also compact.
The proof below is taken from Engelking's General Topology, in the book this is Theorem 3.7.2.
Proof: Let$\{U_s\}_{s\in S}$ be a family of open subsets of $X$ such that $$f^{-1}(Z)\subseteq\bigcup_{s\in S}U_s.$$ We want to find a finite $S_0\subseteq S$ such that $$f^{-1}(Z)\subseteq\bigcup_{s\in S_0}U_s.$$
Let $\mathcal T=\{T\subseteq S\mid T\text{ is finite}\}$ and for $T\in\mathcal T$ let $U_T=\bigcup_{s\in T} U_s$, in other words $\{U_T\mid T\in \mathcal T\}$ is the family of all open sets that can be obtained as a finite union of the $U_s$. Now for $z\in Z$ we know that $f^{-1}(z)$ is compact, which implies that $f^{-1}(z)$ is contained in $U_{T_z}$ for some $T_z\in\mathcal T$. Moreover we have $$z\in Y\setminus f(X\setminus U_{T_z}),$$ and so
$$Z\subseteq \bigcup_{z\in Z} Y\setminus f(X\setminus U_{T_z}).$$
Since $f$ is closed $Y\setminus f(X\setminus U_{T_z})$ is open for all $z\in Z$, so by compactness of $Z$ we can find finitely many $z_i\in Z$ such that, denoting $U_{T_{z_i}}$ by $U_{T_i}$ for simplicity, we have $$Z\subseteq\bigcup_i Y\setminus f(X\setminus U_{T_i}).$$
But now we have
\begin{align}
f^{-1}(Z)&\subseteq \bigcup_i f^{-1}(Y\setminus f(X\setminus U_{T_i}))=\bigcup_i (X\setminus f^{-1}(f(X\setminus U_{T_i}))\\
&\subseteq\bigcup_i(X\setminus(X\setminus U_{T_i}))=\bigcup_i U_{T_i}=\bigcup_{s\in S_0}U_s,
\end{align}
where $S_0=\bigcup_i T_i$. $\square$
I think the method you propose could work and I suppose you mean to say that $O$ is open, in which case you can use a property of compact spaces which says that every open cover of a compact set has a finite subcover.
– Eugaurie Sep 08 '21 at 07:50