We present a general variational principle for the dynamics of impurity particles immersed in a quantum-mechanical medium. By working within the Heisenberg picture and constructing approximate time-dependent impurity operators, we can take the medium to be in any mixed state, such as a thermal state. Our variational method is consistent with all conservation laws and, in certain cases, it is equivalent to a finite-temperature Green's function approach. As a demonstration of our method, we consider the dynamics of heavy impurities that have suddenly been introduced into a Fermi gas at finite temperature. Using approximate time-dependent impurity operators involving only one particle-hole excitation of the Fermi sea, we find that we can successfully model the results of recent Ramsey interference experiments on 40 K atoms in a 6 Li Fermi gas [M. Cetina et al., Science 354, 96 (2016)]. We also show that our approximation agrees well with the exact solution for the Ramsey response of a fixed impurity at finite temperature. Our approach paves the way for the investigation of impurities with dynamical degrees of freedom in arbitrary quantum-mechanical mediums.arXiv:1805.10013v2 [cond-mat.quant-gas]