[guided]We compute the energy variation by differentiating the integrand first, then using integration by parts to move the derivative off the variation field. The variation is the smooth map $\Psi:(-\varepsilon,\varepsilon)\times \Omega \to N$ defined by $\Psi(t,x)=u_t(x)$, with $u_0=u$, and there is a compact set $K\subset\Omega$ such that $u_t=u$ outside $K$ for all sufficiently small $|t|$. Its variation field is the section $W:\Omega \to u^*TN$ defined by $W(x)=\left.\frac{\partial u_t(x)}{\partial t}\right|_{t=0}$.
The compact support of the variation is the hypothesis that will remove all boundary terms and localize differentiation under the integral sign.
Fix a local $g$-orthonormal frame $e_1,\dots,e_m$. The energy density is
\begin{align*}
\frac{1}{2}|du_t|_{g,h}^2
=
\frac{1}{2}\sum_{i=1}^m h(du_t(e_i),du_t(e_i)).
\end{align*}
Differentiating this expression with respect to $t$ and using compatibility of the Levi-Civita connection of $N$ with $h$ gives
\begin{align*}
\left.\frac{d}{dt}\right|_{t=0}\frac{1}{2}|du_t|_{g,h}^2
=
\sum_{i=1}^m h\left(\left.\nabla^N_{\partial_t}du_t(e_i)\right|_{t=0},du(e_i)\right).
\end{align*}
To justify the commutation identity, regard $\partial_t$ and the lifted vector field $e_i$ as vector fields on the product $(-\varepsilon,\varepsilon)\times \Omega$. They commute, so $[\partial_t,e_i]=0$. Applying the torsion-free identity for the Levi-Civita connection of $N$ to the map $\Psi$ gives
\begin{align*}
\nabla^N_{\partial_t}d\Psi(e_i)-\nabla^N_{e_i}d\Psi(\partial_t)=d\Psi([\partial_t,e_i])=0.
\end{align*}
Since $d\Psi(e_i)=du_t(e_i)$ and $d\Psi(\partial_t)=\partial_t u_t$, evaluating at $t=0$ gives
\begin{align*}
\left.\nabla^N_{\partial_t}du_t(e_i)\right|_{t=0}=\nabla^{u^*TN}_{e_i}W.
\end{align*}
Therefore
\begin{align*}
\left.\frac{d}{dt}\right|_{t=0}\frac{1}{2}|du_t|_{g,h}^2
=
\sum_{i=1}^m h(\nabla^{u^*TN}_{e_i}W,du(e_i)).
\end{align*}
Now we identify this expression as a divergence minus the tension pairing. Define the vector field $Z$ on $\Omega$ by
\begin{align*}
g(Z,X)=h(W,du(X))
\end{align*}
for every smooth vector field $X$ on $\Omega$. This is the natural vector field because its divergence differentiates exactly the scalar pairing $h(W,du(e_i))$. Since $W$ has compact support in $\Omega$, the vector field $Z$ also has compact support in $\Omega$.
Using the definition of divergence in the local orthonormal frame,
\begin{align*}
\operatorname{div}_g Z
=
\sum_{i=1}^m e_i\bigl(g(Z,e_i)\bigr)
-
\sum_{i=1}^m g(Z,\nabla^g_{e_i}e_i).
\end{align*}
Substituting $g(Z,X)=h(W,du(X))$ gives
\begin{align*}
\operatorname{div}_g Z
=
\sum_{i=1}^m e_i\bigl(h(W,du(e_i))\bigr)
-
\sum_{i=1}^m h(W,du(\nabla^g_{e_i}e_i)).
\end{align*}
Expanding the derivative of the $h$-pairing yields
\begin{align*}
\operatorname{div}_g Z
=
\sum_{i=1}^m h(\nabla^{u^*TN}_{e_i}W,du(e_i))
+
\sum_{i=1}^m h(W,\nabla^{u^*TN}_{e_i}du(e_i))
-
\sum_{i=1}^m h(W,du(\nabla^g_{e_i}e_i)).
\end{align*}
Combining the last two sums gives the trace of $\nabla du$:
\begin{align*}
\sum_{i=1}^m \left(\nabla^{u^*TN}_{e_i}du(e_i)-du(\nabla^g_{e_i}e_i)\right)
=
\tau_g(u).
\end{align*}
Hence
\begin{align*}
\operatorname{div}_g Z
=
\sum_{i=1}^m h(\nabla^{u^*TN}_{e_i}W,du(e_i))
+
h(W,\tau_g(u)).
\end{align*}
Solving for the differentiated energy density gives
\begin{align*}
\sum_{i=1}^m h(\nabla^{u^*TN}_{e_i}W,du(e_i))
=
\operatorname{div}_g Z-h(W,\tau_g(u)).
\end{align*}
Finally, the compact support of $Z$ in $\Omega$ eliminates the divergence term. Indeed, the [Divergence Theorem](/page/Divergence%20Theorem) applied on a relatively compact open set containing $\operatorname{supp}Z$ gives
\begin{align*}
\int_\Omega \operatorname{div}_g Z\,d\mu_g(x)=0.
\end{align*}
Because $u_t=u$ outside the fixed compact set $K$ for all sufficiently small $|t|$, the energy density and its difference quotient are unchanged outside $K$. Since $\Psi$, $g$, and $h$ are smooth, finitely many coordinate charts covering $K$ give coordinate expressions whose first $t$-derivatives are bounded uniformly for $|t|$ sufficiently small. Hence the ordinary parameter differentiation theorem permits differentiation under the integral sign at $t=0$. Therefore
\begin{align*}
\left.\frac{d}{dt}\right|_{t=0}\frac{1}{2}\int_\Omega |du_t|_{g,h}^2\,d\mu_g(x)=-\int_\Omega h(W,\tau_g(u))\,d\mu_g(x).
\end{align*}
This is the Euler-Lagrange identity for the Dirichlet energy: the only possible obstruction to stationarity against compactly supported variations is the tension field.[/guided]