Context. In very young clusters, stellar age distribution is empirical proof of the duration of star cluster formation and thus it gives indications of the physical mechanisms involved in the star formation process. Determining the amount of interstellar extinction and the correct reddening law are crucial steps to derive fundamental stellar parameters and in particular accurate ages from the Hertzsprung-Russell diagram. Aims. In this context, we seek to derive accurate stellar ages for NGC 6530, the young cluster associated with the Lagoon Nebula to infer the star formation history of this region. Methods. We used the Gaia-ESO survey observations of the Lagoon Nebula, together with photometric literature data and Gaia DR2 kinematics, to derive cluster membership and fundamental stellar parameters. Using spectroscopic effective temperatures, we analysed the reddening properties of all objects and derived accurate stellar ages for cluster members. Results. We identified 652 confirmed and 9 probable members. The reddening inferred for members and non-members allows us to distinguish foreground objects, mainly main-sequence stars, and background objects, mainly giants, and to trace the three-dimensional structure of the nebula. This classification is in agreement with the distances inferred from Gaia DR2 parallaxes for these objects. Finally, we derive stellar ages for 382 confirmed cluster members for which we obtained the individual reddening values. In addition, we find that the gravity-sensitive γ index distribution for the M-type stars is correlated with stellar age. Conclusions. For all members with Teff < 5500 K, the mean logarithmic age is 5.84 (units of years) with a dispersion of 0.36 dex. The age distribution of stars with accretion or discs, i.e. classical T Tauri stars with excess (CTTSe), is similar to that of stars without accretion and without discs, i.e. weak T Tauri stars with photospheric emission (WTTSp). We interpret this dispersion as evidence of a real age spread since the total uncertainties on age determinations, derived from Monte Carlo simulations, are significantly smaller than the observed spread. This conclusion is supported by evidence of the decrease of the gravity-sensitive γ index as a function of stellar ages. The presence of a small age spread is also supported by the spatial distribution and kinematics of old and young members. In particular, members with accretion or discs, formed in the last 1 Myr, show evidence of subclustering around the cluster centre, in the Hourglass Nebula and in the M8-E region, suggesting a possible triggering of star formation events by the O-type star ionization fronts.