Seismic moment and the corresponding moment magnitude Mw are classically obtained from the spectrum of far-field body waves. Near-field records are generally not used for that purpose, particularly in the case of large earthquakes because different types of wave arrive simultaneously, preventing the definition of a simple relation between the seismic moment and the spectrum. We developed an original method to determine Mw from the displacement spectra of near-field records. The spectral amplitude at low frequency obtained from the real records is compared to that of synthetic records computed using kinematic rupture models scaled with Mw. Synthetic records are computed and averaged for various fault orientations and for epicentral distances ranging from 1 to 100 km. The initial portion of the spectrum affected by baseline shift in the acceleration records is automatically identified and removed by high-pass filtering using a cutoff frequency adapted to each station. The synthetic spectral values as a function of moment magnitude, epicentral distance, and filtering are computed only once and stored in tables. The spectral amplitudes of the real records are simply interpolated in the tables of synthetic data, allowing a fast determination of Mw. The method has been validated using 22 shallow earthquakes (depth<50 km) with magnitude ranging from 3.9 to 7.7. We show that a window of 80 sec of signal after the earthquake origin time provides robust values of Mw for the whole magnitude range considered here. Shorter time windows may be used but with Mw underestimated for large events. The method is well suited for near real-time fast determination of Mw.