We study the effect of temporal correlation in a Langevin equation describing nonadiabatic dynamics at metal surfaces. For a harmonic oscillator, the Langevin equation preserves the quantum dynamics exactly and it is demonstrated that memory effects are needed in order to conserve the ground state energy of the oscillator. We then compare the result of Langevin dynamics in a harmonic potential with a perturbative master equation approach and show that the Langevin equation gives a better description in the nonperturbative range of high temperatures and large friction. Unlike the master equation, this approach is readily extended to anharmonic potentials. Using density functional theory, we calculate representative Langevin trajectories for associative desorption of N-2 from Ru(0001) and find that memory effects lower the dissipation of energy. Finally, we propose an ab initio scheme to calculate the temporal correlation function and dynamical friction within density functional theory.