[proofplan]
We prove the equivalence "$K$ is a local field $\iff$ $\mathcal{O}_K$ is compact" in two directions. For the forward direction, we use the finiteness of the residue field to show that each quotient $\mathcal{O}_K/\pi^n \mathcal{O}_K$ is finite, then extract a convergent subsequence from any sequence in $\mathcal{O}_K$ via a diagonal argument. For the reverse direction, we deduce completeness from compactness of the closed subsets $\pi^{-n}\mathcal{O}_K$, and finiteness of the residue field from the fact that a compact discrete space is finite.
[/proofplan]
[step:Show that compactness of $\mathcal{O}_K$ implies completeness of $K$]
Assume $\mathcal{O}_K$ is compact. For each $n \geq 0$, the map $\mu_n: \mathcal{O}_K \to \pi^{-n}\mathcal{O}_K$ defined by $x \mapsto \pi^{-n} x$ is a homeomorphism (it is bijective with continuous inverse $y \mapsto \pi^n y$, and both maps are continuous since multiplication by a fixed element is continuous in a valued field). Since $\mathcal{O}_K$ is compact, $\pi^{-n}\mathcal{O}_K$ is compact, hence complete (compact subsets of metric spaces are complete).
Now let $(x_m)_{m \geq 0}$ be a Cauchy sequence in $K$. Since the terms eventually satisfy $|x_m| \leq C$ for some bound $C$ (Cauchy sequences are bounded), and the absolute value takes values in $\{0\} \cup \{|\pi|^k : k \in \mathbb{Z}\}$, there exists $n \geq 0$ with $|x_m| \leq |\pi|^{-n}$ for all sufficiently large $m$. Hence the tail of the sequence lies in $\pi^{-n}\mathcal{O}_K$, which is complete. So $(x_m)$ converges in $\pi^{-n}\mathcal{O}_K \subseteq K$, and $K$ is complete.
[guided]
We want to show that if $\mathcal{O}_K$ is compact, then $K$ is complete. The idea is that every Cauchy sequence in $K$ is eventually bounded, hence eventually lies inside one of the compact (and therefore complete) subsets $\pi^{-n}\mathcal{O}_K$.
Why is $\pi^{-n}\mathcal{O}_K$ compact? The map $x \mapsto \pi^{-n}x$ is a homeomorphism from $\mathcal{O}_K$ to $\pi^{-n}\mathcal{O}_K$ (with inverse $y \mapsto \pi^n y$; both are continuous since scalar multiplication is continuous). The continuous image of a compact set is compact.
Why is a Cauchy sequence eventually bounded? If $(x_m)$ is Cauchy, then for $\varepsilon = 1$, there exists $N$ such that $|x_m - x_{m'}| < 1$ for all $m, m' \geq N$. Then $|x_m| \leq \max(|x_m - x_N|, |x_N|) \leq \max(1, |x_N|)$ for all $m \geq N$. Since $|x_N| = |\pi|^{-k}$ for some $k \in \mathbb{Z}$ (or $x_N = 0$), we get $|x_m| \leq |\pi|^{-n}$ for some fixed $n$ and all $m \geq N$. So the tail lies in $\pi^{-n}\mathcal{O}_K$, which is compact and hence complete. Completeness of $\pi^{-n}\mathcal{O}_K$ guarantees convergence.
[/guided]
[/step]
[step:Show that compactness of $\mathcal{O}_K$ implies finiteness of $k_K$]
The reduction map $\rho: \mathcal{O}_K \to k_K = \mathcal{O}_K/\mathfrak{m}_K$ sending $x \mapsto x + \mathfrak{m}_K$ is continuous when $k_K$ carries the discrete topology. To see this: for any $\bar{a} \in k_K$, the preimage $\rho^{-1}(\bar{a}) = a + \mathfrak{m}_K$ is the closed ball $\{y \in \mathcal{O}_K : |y - a| < 1\}$, which is open in $\mathcal{O}_K$ (as it is an open ball of radius $1$). So each singleton $\{\bar{a}\}$ has open preimage, confirming continuity.
Since $\rho$ is continuous and surjective, $k_K = \rho(\mathcal{O}_K)$ is a continuous image of the compact space $\mathcal{O}_K$, hence compact. A compact discrete space is finite (every point is open, so the open cover $\{\{a\} : a \in k_K\}$ has no proper subcover, and compactness forces the cover to be finite). Therefore $k_K$ is finite.
[/step]
[step:Prove that finiteness of $k_K$ and completeness imply compactness of $\mathcal{O}_K$ via a diagonal argument]
Assume $K$ is a local field, so $k_K$ is finite (say $|k_K| = q$) and $K$ is complete. We show $\mathcal{O}_K$ is sequentially compact, which implies compactness since $\mathcal{O}_K$ is a metric space.
[claim:Each quotient $\mathcal{O}_K/\pi^n \mathcal{O}_K$ is finite of order $q^n$]
For $n = 1$, $\mathcal{O}_K/\pi \mathcal{O}_K = k_K$ has $q$ elements by hypothesis. For the inductive step, consider the short exact sequence of abelian groups
\begin{align*}
0 \to \pi^n \mathcal{O}_K / \pi^{n+1} \mathcal{O}_K \to \mathcal{O}_K / \pi^{n+1} \mathcal{O}_K \to \mathcal{O}_K / \pi^n \mathcal{O}_K \to 0.
\end{align*}
The map $\mathcal{O}_K/\pi \mathcal{O}_K \to \pi^n \mathcal{O}_K / \pi^{n+1} \mathcal{O}_K$ sending $\bar{a} \mapsto \pi^n a + \pi^{n+1}\mathcal{O}_K$ is a well-defined bijection (surjectivity: every element of $\pi^n \mathcal{O}_K$ has the form $\pi^n a$; injectivity: $\pi^n a \in \pi^{n+1}\mathcal{O}_K$ iff $a \in \pi \mathcal{O}_K$). So $|\pi^n \mathcal{O}_K / \pi^{n+1} \mathcal{O}_K| = q$, and $|\mathcal{O}_K / \pi^{n+1}\mathcal{O}_K| = q \cdot |\mathcal{O}_K/\pi^n \mathcal{O}_K| = q^{n+1}$.
[/claim]
[proof]
Proved inline above.
[/proof]
Let $(x_i)_{i \geq 1}$ be a sequence in $\mathcal{O}_K$. Since $\mathcal{O}_K/\pi \mathcal{O}_K$ is finite, there exist infinitely many indices $i$ for which $x_i$ falls in the same coset modulo $\pi$. Extract a subsequence $(x_{1,i})_{i \geq 1}$ that is constant modulo $\pi \mathcal{O}_K$.
Repeat: since $\mathcal{O}_K/\pi^2 \mathcal{O}_K$ is finite, pass to a further subsequence $(x_{2,i})_{i \geq 1}$ of $(x_{1,i})$ that is constant modulo $\pi^2 \mathcal{O}_K$. Continuing, for each $n \geq 1$, extract $(x_{n,i})_{i \geq 1}$ as a subsequence of $(x_{n-1,i})$ that is constant modulo $\pi^n \mathcal{O}_K$.
Form the diagonal subsequence $y_j := x_{j,j}$ for $j \geq 1$. For any $n \geq 1$ and $j, j' \geq n$, the terms $y_j = x_{j,j}$ and $y_{j'} = x_{j',j'}$ are both members of the subsequence $(x_{n,i})_{i \geq 1}$ (since for $j \geq n$, $x_{j,j}$ appears in the $n$-th subsequence). Hence $y_j \equiv y_{j'} \pmod{\pi^n}$, giving $|y_j - y_{j'}| \leq |\pi|^n$. Since $|\pi|^n \to 0$ as $n \to \infty$, the sequence $(y_j)$ is Cauchy. By completeness of $K$, it converges to some $y \in K$. Since $|y_j| \leq 1$ for all $j$, we have $|y| \leq 1$, so $y \in \mathcal{O}_K$.
[guided]
This is the standard diagonal argument, adapted to the $\pi$-adic setting. The finiteness of the residue field is what makes the pigeonhole principle work at each stage.
**Stage 1:** The quotient $\mathcal{O}_K/\pi \mathcal{O}_K = k_K$ has $q$ elements. By the pigeonhole principle, infinitely many terms of $(x_i)$ land in the same coset. Extract these as $(x_{1,i})$.
**Stage 2:** The quotient $\mathcal{O}_K/\pi^2 \mathcal{O}_K$ has $q^2$ elements. Among the terms of $(x_{1,i})$, infinitely many share the same coset modulo $\pi^2$. Extract these as $(x_{2,i})$.
**Stage $n$:** Repeat with $\mathcal{O}_K/\pi^n \mathcal{O}_K$ (which has $q^n$ elements) to get $(x_{n,i})$.
**Diagonal construction:** The diagonal subsequence $(x_{j,j})$ is eventually a subsequence of every $(x_{n,i})$: for $j \geq n$, the term $x_{j,j}$ appears in the $n$-th extracted subsequence. So for $j, j' \geq n$, we have $x_{j,j} \equiv x_{j',j'} \pmod{\pi^n}$, giving $|x_{j,j} - x_{j',j'}| \leq |\pi|^n \to 0$.
This makes $(x_{j,j})$ Cauchy, and completeness provides the limit in $\mathcal{O}_K$.
Why does sequential compactness imply compactness here? Because $\mathcal{O}_K$ is a metric space (metrized by the absolute value), and for metric spaces sequential compactness and compactness are equivalent.
[/guided]
[/step]