  A semilinear wave equation with slowly varying wave speed is considered in
one to three space dimensions on a bounded interval, a rectangle or a box,
respectively. It is shown that the action, which is the harmonic energy divided
by the wave speed and multiplied with the diameter of the spatial domain, is an
adiabatic invariant: it remains nearly conserved over long times, longer than
any fixed power of the time scale of changes in the wave speed in the case of
one space dimension, and longer than can be attained by standard perturbation
arguments in the two- and three-dimensional cases. The long-time
near-conservation of the action yields long-time existence of the solution. The
proofs use modulated Fourier expansions in time.
