Solution 1:

Since $X$ and $Y$ are metric spaces, it suffices to show that if $\langle x_n:n\in\Bbb N\rangle$ is a convergent sequence in $X$ with limit $x$, then $\langle f(x_n):n\in\Bbb N\rangle$ is a convergent sequence in $Y$ with limit $f(x)$; in words, f preserves convergent sequences.

Suppose that $\langle x_n:n\in\Bbb N\rangle$ converges to $x$ in $X$. If there is an $n_0\in\Bbb N$ such that $x_n=x$ for all $n\ge n_0$, it’s trivially true that $\langle f(x_n):n\in\Bbb N\rangle\to f(x)$, so assume (by passing to a subsequence if necessary) that $\langle x_n:n\in\Bbb N\rangle$ is a sequence of distinct points. (Since $\langle x_n:n\in\Bbb N\rangle$ converges to $x$ and is not eventually constant at $x$, it cannot have a constant infinite subsequence: for each $n\in\Bbb N$ there must be an $m>n$ such that $x_k\ne x_n$ whenever $k\ge m$.)

For each $n\in\Bbb N$ set $K_n=\{x\}\cup\{x_k:k\ge n\}$; each $K_n$ is compact and infinite. (Why?) By hypothesis, therefore, each $f[K_n]$ is compact.

For convenience let $y=f(x)$, and let $y_n=f(x_n)$ and $H_n=f[K_n]$ for $n\in\Bbb N$. By hypothesis each $H_n$ is compact and infinite, so each contains a limit point. Fix $n\in\Bbb N$. For each $k\ge n$, $Y\setminus H_{k+1}$ is an open nbhd of $y_k$ that contains only finitely many points of $H_n$ (why?), so $y_k$ can’t be a limit point of $H_n$. Thus, for each $n\in\Bbb N$ the only possible limit point of $H_n$ is $y$ itself. From here you should be able to prove without too much trouble that $\langle y_n:n\in\Bbb N\rangle\to y$ and hence that $f$ is continuous.