Solution (source code)

= Solution

Vary the <scalar field> with compactly supported variation, leaving the <metric tensor> fixed. The <action> variation is
$$
\delta S_M=\int d^4x\sqrt{-g}
\left[-g^{\mu\nu}\partial_\mu\phi\,\partial_\nu\delta\phi-V_{,\phi}\delta\phi\right].
$$
<Integration by parts> moves the derivative from $\delta\phi$ and gives the <Euler-Lagrange equation>
$$
\Box_g\phi-V_{,\phi}=0,\qquad
\Box_g\phi=\frac1{\sqrt{-g}}\partial_\mu\left(\sqrt{-g}\,g^{\mu\nu}\partial_\nu\phi\right).
$$
For the <FRW metric>, $\sqrt{-g}=a^3$, so the <covariant wave operator> becomes
$$
\Box_g\phi=-a^{-3}\partial_t(a^3\dot\phi)+a^{-2}\nabla^2\phi
=-\ddot\phi-3H\dot\phi+a^{-2}\nabla^2\phi.
$$
Rearranging gives the requested <scalar field> evolution:
$$
\boxed{\ddot\phi+3\frac{\dot a}{a}\dot\phi-a^{-2}\nabla^2\phi=-V_{,\phi}.}
$$
The damping term is <Hubble friction>; it comes from the expanding volume factor $a^3$, not from a microscopic dissipative force.