My first answer was not correct. Let's try something else.
Consider
a partition of unity $\left(U_{i},\varphi_{i}\right)$ subordinate
to a countable open cover of $M$ by open sets $U_{i}$ with compact
closure. Define $\theta\colon M\rightarrow\mathbb{R}$ by $\theta=\sum_{i=1}^{\infty}i\varphi_{i}$.
The function $\theta$ is well-defined due to the properties of partitions
of unity. We see that, for every integer $j$ :
$$
\theta^{-1}\left(\left[-j,j\right]\right)\subset\bigcup_{i=1}^{j}\left\{ x:\varphi_{i}\left(x\right)\ne0\right\} ,
$$
which has a compact closure. Hence $\theta^{-1}\left(\left[-j,j\right]\right)$
is a compact set.