The nonperturbative Hartree approximation is applied to the study of the relaxational dynamics of the two-dimensional random sine-Gordon model. This model describes crystalline surfaces upon disordered substrates, two-dimensional vortex arrays in disordered type II superconducting films, the vortex-free random-field XY model, and other physical systems. We find that the fluctuation-dissipation (FDT) theorem is violated below the critical temperature T-c for large enough times t > t*, where t* is the ''barrier-crossing'' time which diverges with the size of the system. Above T-c the dynamics obeys FDT for all times and the local autocorrelation function q(t) diverges as similar to TInt. The transition is second order for g < g(tr) where g is the effective coupling to the random-phase periodic potential. In this regime below T-c, as t --> t*, q(t) approaches a finite value q*(T) [but diverges as (T-c - T)(-1) as T --> T-c(-)]. For g > g(tr) the transition is first order and occurs at the higher g-dependent temperature T-c(g). As t --> t*, the autocorrelations saturate below T-c(g) to a value q*(g,T) that remains finite as T --> T-c(-)(g). In both regimes we find that the ergodic saturation of q(t) to its ''one valley'' value has the form q(t) = q* - ct(-v) (as t --> t(*-)). For t > t* the dynamics is nonergodic. Marginally stable solutions are found within the quasi-FDT approach. They are characterized by a FDT breaking parameter m(T) = pi T (1 - e(-4 pi 4q*/T)) < 1, [m(T) = 1 for T > T-c where FDT holds]. The static correlations behave as T In \(x) over right arrow\ for \(x) over right arrow\ < xi with xi similar to exp[A/(T-c- T)]. For scales \(x) over right arrow\ > xi they behave as (T/m)In\(x) over right arrow\. Near T-c, T/m similar to T-c but it increases from this value as T is lowered below T-c. The results are compared with dynamic renormalization-group predictions, with equilibrium results obtained by a similar variational approximation with a one-step replica symmetry breaking, and with recent Monte Carlo simulations.