We present a dispersion-inversion method which inverts for the P-velocity model from guided waves propagating in wave guides of arbitrary geometry. Its misfit function is the squared summation of differences between the predicted and observed dispersion curves of guided P waves, and the inverted result is a high-resolution estimate of the near-surface P-velocity model. We denote this procedure as wave-equation dispersion inversion of guided P waves (WDG), which is valid for near-surface waveguides with irregular layers and does not require a high-frequency approximation. It is more robust than full waveform inversion and can sometimes provide velocity models with higher resolution than wave-equation traveltime tomography. Both the synthetic-data and field data results demonstrate that WDG for guided P waves can accurately invert for complex P-velocity models at the near surface of the Earth.