Finding a local Hamiltonian having a given many-body wavefunction as its ground state is a serious challenge of fundamental importance in quantum technologies. Here we introduce a method, inspired by quantum annealing, that efficiently performs this task through an artificial inverse dynamics: a slow deformation of the state generates an adiabatic evolution of the corresponding Hamiltonian. We name this approach inverse quantum annealing. This method only requires the knowledge of local expectation values. As an example, we apply inverse quantum annealing to find the local Hamiltonian of fermionic Gaussian states.