Recorded surface waves often provide reasonable estimates of the S-wave velocity in the near surface. However, existing algorithms are mainly based on the 1D layered-model assumption and require picking the dispersion curves either automatically or manually. We have developed a wave-equation-based inversion algorithm that inverts for S-wave velocities using fundamental and higher mode Rayleigh waves without picking an explicit dispersion curve. Our method aims to maximize the similarity of the phase velocity spectrum () of the observed and predicted surface waves with all Rayleigh-wave modes (if they exist) included in the inversion. The spectrum is calculated using the linear Radon transform applied to a local similarity-based objective function; thus, we do not need to pick velocities in spectrum plots. As a result, the best match between the predicted and observed spectrum provides the optimal estimation of the S-wave velocity. We derive S-wave velocity updates using the adjoint-state method and solve the optimization problem using a limited-memory Broyden-Fletcher-Goldfarb-Shanno algorithm. Our method excels in cases in which the S-wave velocity has vertical reversals and lateral variations because we used all-modes dispersion, and it can suppress the local minimum problem often associated with full-waveform inversion applications. Synthetic and field examples are used to verify the effectiveness of our method.