  Let $M$ be a smooth, compact, connected, oriented Riemannian manifold, and
let $\imath: M \to \mathbb R^d$ be an isometric embedding. We show that a
Sobolev map $f: M \to M$ which has the property that the differential $df(q)$
is close to the set $SO(T_q M, T_{f(q)} M)$ of orientation preserving
isometries (in an $L^p$ sense) is already $W^{1,p}$ close to a global isometry
of $M$. More precisely we prove for $p \in (1,\infty)$ the optimal linear
estimate $$\inf_{\phi \in \mathrm{Isom}_+(M)} \| \imath \circ f - \imath \circ
\phi\|_{W^{1,p}}^p \le C E_p(f)$$ where $$ E_p(f) := \int_M {\rm dist}^p(df(q),
SO(T_q M, T_{f(q)} M)) \, d{\rm vol}_M$$ and where $\mathrm{Isom}_+(M)$ denotes
the group of orientation preserving isometries of $M$.
  This extends the Euclidean rigidity estimate of Friesecke-James-M\"uller
[Comm. Pure Appl. Math. {\bf 55} (2002), 1461--1506] to Riemannian manifolds.
It also extends the Riemannian stability result of Kupferman-Maor-Shachar
[Arch. Ration. Mech. Anal. {\bf 231} (2019), 367--408] for sequences of maps
with $E_p(f_k) \to 0$ to an optimal quantitative estimate.
  The proof relies on the weak
  Riemannian Piola identity of Kupferman-Maor-Shachar, a uniform $C^{1,\alpha}$
approximation through the harmonic map heat flow, and a linearization argument
which reduces the estimate to the well-known Riemannian version of Korn's
inequality.
