This is an exercise from Rudin's 'Functional Analysis':
Suppose that $X$ and $K$ are metric spaces, that $K$ is compact, and that the graph $f:X\to K$ is a closed subset of $X\times K$. Prove that $f$ is continuous.
So we have $\mathscr{G}=\{(x,f(x)):x\in X\}$, which is closed in $X\times K$ with $K$ compact.
I was thinking of fixing $x_{0}$ in $K$ and then considering a sequence $(x_{n})\subset X$ converging to $x_{0}$...But ultimately, I want to know how can I exploit the compactness of $K$ to solve the question? Moreover, the question states that the compactness of $K$ cannot be omitted from the hypotheses, even when $X$ is compact.
Hint: Let $x_n$ be a sequence of $X$ which converges towards $x$, since $K$ is compact we can extract $x_{l(n)}$ such that $f(x_{l(n)})$ converges towards $y$. Since $(x_{l(n)},f(x_{l(n)}))$ is in the graph and the graph is closed, $(x,y)$ is in the graph. This implies that $f(x)=y$ and $f(y)$ is adherent to every convergent subsequence of $f(x_n)$ thus $f$ is continue since $K$ is compact.