We derive an exact mapping from the action of nonequilibrium dynamical mean-field theory (DMFT) to a single-impurity Anderson model (SIAM) with time-dependent parameters, which can be solved numerically by exact diagonalization. The representability of the nonequilibrium DMFT action by a SIAM is established as a rather general property of nonequilibrium Green functions. We also obtain the nonequilibrium DMFT equations using the cavity method alone. We show how to numerically obtain the SIAM parameters using Cholesky or eigenvector matrix decompositions. As an application, we use a Krylov-based time propagation method to investigate the Hubbard model in which the hopping is switched on, starting from the atomic limit. Possible future developments are discussed.