A topological space $X$ is called pseudo-compact if every continuous real-valued function from $X$ is bounded. In general, the notion of pseudo-compactness is not equivalent to compactness, although it is for metric spaces.
Now, clearly, if $X$ is a compact space then every continuous real-valued function $f$ from $X$ attains its maximum, i.e. there exists $x \in X$ such that for all $z \in X$ we have $f(x) \geq f(z)$. This is because the image of compact spaces under continuous maps is compact and therefore $f(X) \subseteq \mathbb{R}$ (as a bounded and closed set) contains its supremum.
Question: Let $X$ be a topological space such that every continuous real-valued function attains its maximum. Must $X$ be a compact space?
My guess would be that there exists a counterexample, but I was not able to construct one.
Thank you in advance for your help!