We study surface-induced spin relaxation with a laser-assisted magnetic resonance experiment. Optical pumping with polarization-modulated light in a transverse magnetic field creates the spin polarization. For detection a probe laser beam is reflected at the surface and the change of its polarization is monitored. We present a comprehensive theoretical description, taking into account the spin relaxation at the surface, which leads to a spatially inhomogeneous magnetization near the surface as a result of the transient behavior of the atoms in this region. Analytical expressions are derived for the magnetic resonance signal, which show that the wall relaxation causes a clear modification of the line shape, characterized by pronounced wings. The experimental results obtained with bare and silicone-coated Pyrex-glass surfaces are well described by the theory. The bare glass surface causes strong relaxation, whereas the siliconecoated surface is only weakly depolarizing. The analysis of the magnetic-resonance line shape indicates that the depolarization probability per wall collision is &0.01 in the latter case. The results are compared with corresponding results from the analysis of the optical resonance line measured with the same setup. Both types of measurements can be interpreted within the same theoretical framework and are fully consistent with one another.