A measurement of the virtual-photon asymmetry A_2(x,Q^2) and of the spin-structure function g_2(x,Q^2) of the proton are presented for the kinematic range 0.004 < x < 0.9 and 0.18 GeV^2 < Q^2 < 20 GeV^2. The data were collected by the HERMES experiment at the HERA storage ring at DESY while studying inclusive deep-inelastic scattering of 27.6 GeV longitudinally polarized leptons off a transversely polarized hydrogen gas target. The results are consistent with previous experimental data from CERN and SLAC. For the x-range covered, the measured integral of g_2(x) converges to the null result of the Burkhardt-Cottingham sum rule. The x^2 moment of the twist-3 contribution to g_2(x) is found to be compatible with zero.