Proof: From the basic properties of the infimum, we know that we can find elements in a set that are arbitrarily close to its infimum. Then there exists a sequence $(|x_n-y_n|)$ such that $\lim_{n\to \infty} |x_n-y_n|= dis(A,B)$ where $x_n \in A$ and $y_n \in B$ for all n.
Because A is compact, $\{x_n\}$ has a convergent subsequence $\{x_{n_k}\}$, where its limit is an element $a \in A$ as a compact set is closed.
As every convergent sequence is bounded, we know that $(|x_n-y_n|)$ is bounded. Also, $\{x_n\}$ is obviously bounded because A is compact. From $|y_n| =|x_n-(x_n-y_n)| \leq |x_n|+|x_n-y_n|$, we see that $\{y_n\}$ is also bounded. In particular, $\{y_{n_k}\}$ is bounded. By Bolzano-Weirstrass Theorem, $\{y_{n_k}\}$ has a convergent subsequence: $y_{n_{k_l}} \to b$ as $l \to \infty$. Since B is closed, we have $b \in B$. We also have $x_{n_{k_l}} \to a \in A$ as $l \to \infty$.
Therefore, $dis(A,B)=\lim_{n\to \infty} |x_n-y_n|=\lim_{n\to \infty} |x_{n_{k_l}}-y_{n_{k_l}}| = |a-b|$, for the elements $a \in A$ and $b \in B$ found above.