By contradiction. Suppose $X$ is not compact; therefore one can pick an infinite sequence $x_1,x_2,...$ that does not accumulate at any point in $X$.
Then pick an unbounded function on that sequence, say $f(x_n)=n$, and turn it into a continuous one. This is possible because topology of a metric allows interpolation function between disjoint close subsets.
For example, you can enclose each $x_n$ into balls $x_n\in B_{\epsilon_n}$ such as $B_{\epsilon_n}$ are pairwise disjoint, then set $f(x)=0,x\in (X-\cup B_{\epsilon_n})$ and $f(x)=n(1-\frac{d(x,x_n)}{\epsilon_n}),x\in B_{\epsilon_n}$