[proofplan]
Fix a direction $v \in \mathbb{R}^n$ and restrict $f$ to the line through $a$ in that direction. Openness of $U$ ensures that this line restriction is defined on a two-sided interval around $0$, and the local extremum of $f$ at $a$ becomes a one-variable local extremum at $0$. Comparing the difference quotients from positive and negative values of the parameter forces the derivative at $0$, hence the [directional derivative](/page/Directional%20Derivative) $D_v f(a)$, to be both nonnegative and nonpositive.
[/proofplan]
[step:Choose a two-sided interval along the direction $v$ inside $U$]
Fix $v \in \mathbb{R}^n$. Let $|\cdot|: \mathbb{R}^n \to [0,\infty)$ denote the Euclidean norm, and for each center $x_0 \in \mathbb{R}^n$ and radius $s > 0$, let
\begin{align*}
B(x_0,s) := \{x \in \mathbb{R}^n : |x - x_0| < s\}
\end{align*}
denote the open Euclidean ball. Since $U$ is open and $a \in U$, there exists $r > 0$ such that $B(a,r) \subset U$.
If $v = 0$, then $a + tv = a$ for every $t \in \mathbb{R}$, so the difference quotient defining the directional derivative is identically zero:
\begin{align*}
\frac{f(a + tv) - f(a)}{t} = 0
\end{align*}
for every $t \ne 0$. Hence $D_0 f(a) = 0$.
Assume now that $v \ne 0$. Define
\begin{align*}
\delta := \frac{r}{|v|}.
\end{align*}
Then for every $t \in (-\delta,\delta)$ we have $|tv| < r$, and therefore $a + tv \in B(a,r) \subset U$. Thus the line restriction
\begin{align*}
g: (-\delta,\delta) \to \mathbb{R}, \qquad g(t) := f(a + tv)
\end{align*}
is well-defined.
[/step]
[step:Transfer the local extremum from $f$ to the one-variable restriction]
Since $a$ is a local maximum or a local minimum of $f$ on $U$, there exists $\rho > 0$ such that either
\begin{align*}
f(x) \le f(a) \quad \text{for every } x \in U \cap B(a,\rho)
\end{align*}
or
\begin{align*}
f(x) \ge f(a) \quad \text{for every } x \in U \cap B(a,\rho).
\end{align*}
Set
\begin{align*}
\varepsilon := \min\left\{\delta,\frac{\rho}{|v|}\right\}.
\end{align*}
Then for every $t \in (-\varepsilon,\varepsilon)$ we have $a + tv \in U \cap B(a,\rho)$. Hence $g$ has a local maximum at $0$ in the first case and a local minimum at $0$ in the second case.
[guided]
The purpose of this step is to make the $n$-variable hypothesis usable in one variable. The local extremum assumption says that, near $a$ and inside $U$, the value $f(a)$ dominates all nearby values or is dominated by all nearby values. More precisely, there is a radius $\rho > 0$ such that either
\begin{align*}
f(x) \le f(a) \quad \text{for every } x \in U \cap B(a,\rho)
\end{align*}
or
\begin{align*}
f(x) \ge f(a) \quad \text{for every } x \in U \cap B(a,\rho).
\end{align*}
We also need the points on the line $a + tv$ to stay inside the ball $B(a,\rho)$. Since $v \ne 0$, the condition $a + tv \in B(a,\rho)$ is equivalent to $|t||v| < \rho$. Thus it is enough to require $|t| < \rho/|v|$. Combining this with the earlier domain condition $|t| < \delta$, define
\begin{align*}
\varepsilon := \min\left\{\delta,\frac{\rho}{|v|}\right\}.
\end{align*}
Then for every $t \in (-\varepsilon,\varepsilon)$, the point $a + tv$ lies both in $U$ and in the neighbourhood where the extremum inequality holds. Therefore the one-variable function $g: (-\delta,\delta) \to \mathbb{R}$, defined by $g(t) = f(a + tv)$, has the same type of local extremum at $0$ that $f$ has at $a$.
[/guided]
[/step]
[step:Compare positive and negative difference quotients]
We prove the local maximum case; the local minimum case is identical with the inequalities reversed and is written afterward.
Assume first that $a$ is a local maximum. For every $t \in (0,\varepsilon)$,
\begin{align*}
g(t) - g(0) = f(a + tv) - f(a) \le 0.
\end{align*}
Dividing by the positive number $t$ gives
\begin{align*}
\frac{g(t)-g(0)}{t} \le 0.
\end{align*}
For every $t \in (-\varepsilon,0)$, the same numerator satisfies $g(t)-g(0) \le 0$, but division by the negative number $t$ reverses the inequality:
\begin{align*}
\frac{g(t)-g(0)}{t} \ge 0.
\end{align*}
Since $f$ is differentiable at $a$, the directional derivative in the direction $v$ exists and equals the derivative of $g$ at $0$:
\begin{align*}
D_v f(a) = g'(0) = \lim_{t \to 0}\frac{g(t)-g(0)}{t}.
\end{align*}
The right-hand limit is at most $0$, while the left-hand limit is at least $0$. Because the two-sided limit exists, both one-sided limits are equal, and therefore
\begin{align*}
D_v f(a) = 0.
\end{align*}
If $a$ is a local minimum, then $g(t)-g(0) \ge 0$ for all $t \in (-\varepsilon,\varepsilon)$. For $t > 0$ this gives
\begin{align*}
\frac{g(t)-g(0)}{t} \ge 0,
\end{align*}
and for $t < 0$ it gives
\begin{align*}
\frac{g(t)-g(0)}{t} \le 0.
\end{align*}
Again the two-sided limit exists and must be both at least $0$ and at most $0$, so $D_v f(a)=0$.
[/step]
[step:Conclude for every direction]
The vector $v \in \mathbb{R}^n$ was arbitrary. The case $v=0$ was handled directly, and every nonzero direction satisfies the preceding argument. Hence for every $v \in \mathbb{R}^n$,
\begin{align*}
D_v f(a)=0.
\end{align*}
This proves the theorem.
[/step]