$K\subseteq \mathbb{R}^n$ is a compact space iff every continuous function in $K$ is bounded.
Solution 1:
Let $K$ be a set which is such that every continuous function on it is bounded.
Clearly $K$ itself is bounded, for the function «distance to the origin» is bounded by hypothesis.
Suppose $K$ is not closed, so that there is a point $x$ which is in the closure of $K$ but not in $K$. Consider the function $$f:y\in K\mapsto \frac{1}{d(x,y)}\in\mathbb R,$$ which is clearly well defined and continuous. The choice of $x$ implies more or less immediately that $f$ is not bounded on $K$, so something's amiss...
Solution 2:
A topological space $X$ is called pseudocompact if every continuous function $f: X \rightarrow \mathbb{R}$ is bounded.
The aforelinked wikipedia article does a good job of comparing this condition to other versions of compactness. In particular:
$\bullet$ compact $\implies$ countably compact (i.e., every countable cover has a finite subcover; equivalently, every infinite subset has an $\omega$-accumulation point) $\implies$ pseudocompact.
$\bullet$ A normal Hausdorff space is pseudocompact iff it is countably compact iff it is limit point compact (every infinite subset has an accumulation point).
One of the big theorems in undergraduate analysis is that a metrizable space is limit point compact iff it is compact iff it is sequentially compact, so all notions of compactness mentioned here coincide on the class of metrizable spaces. This provides a more general answer to your question.