Nonlinear dynamics of field maintenance and quasiperiodic relaxation in reversed-field pinches