We apply imaginary-time evolution with the operator e(-iota H) to study relaxation dynamics of gapless quantum antiferromagnets described by the spin-rotation-invariant Heisenberg Hamiltonian H. Using quantum Monte Carlo simulations to obtain unbiased results, we propagate an initial state with maximal order parameter m(s)(z) ( the staggered magnetization) in the z spin direction and monitor the expectation value < m(s)> as a function of imaginary time iota. Results for different system sizes (lengths) L exhibit an initial essentially size independent relaxation of < m(s)> toward its value in the infinite-size spontaneously symmetry broken state, followed by a strongly size dependent final decay to zero when the O(3) rotational symmetry of the order parameter is restored. We develop a generic finite-size scaling theory that shows the relaxation time diverges asymptotically as L-z, where z is the dynamic exponent of the low-energy excitations. We use the scaling theory to develop a practical way of extracting the dynamic exponent from the numerical finite-size data, systematically eliminating scaling corrections. We apply the method to spin-1/2 Heisenberg antiferromagnets on two different lattice geometries: the standard two-dimensional (2D) square lattice and a site-diluted 2D square lattice at the percolation threshold. In the 2D case we obtain z = 2.001(5), which is consistent with the known value z = 2, while for the site-diluted lattice we find z = 3.90(1) or z = 2.056(8) D-f, where D-f = 91/48 is the fractal dimensionality of the percolating system. This is an improvement on previous estimates of z approximate to 3.7. The scaling results also show a fundamental difference between the two cases; for the 2D square lattice, the data can be collapsed onto a common scaling function even when < m(s)> is relatively large, reflecting the Anderson tower of quantum rotor states with a common dynamic exponent z = 2. For the diluted 2D square lattice, the scaling works well only for small < m(s)>, indicating a mixture of different relaxation-time scalings between the low-energy states. Nevertheless, the low-energy dynamic here also corresponds to a tower of excitations.