  An exact invariant is derived for $n$-degree-of-freedom Hamiltonian systems
with general time-dependent potentials. The invariant is worked out in two
equivalent ways. In the first approach, we define a special {\it Ansatz\/} for
the invariant and determine its time-dependent coefficients. In the second
approach, we perform a two-step canonical transformation of the initially
time-dependent Hamiltonian to a time-independent one. The invariant is found to
contain a function of time $f_{2}(t)$, defined as a solution of a linear
third-order differential equation whose coefficients depend in general on the
explicitly known configuration space trajectory that follows from the system's
time evolution. It is shown that the invariant can be interpreted as the time
integral of an energy balance equation. Our result is applied to a
one-dimensional, time-dependent, damped non-linear oscillator, and to a
three-dimensional system of Coulomb-interacting particles that are confined in
a time-dependent quadratic external potential. We finally show that our results
can be used to assess the accuracy of numerical simulations of time-dependent
Hamiltonian systems.
