We show for JET and ASDEX Upgrade, based on Thomson-scattering measurements, a clear correlation of the density limit of the tokamak H-mode high-confinement regime with the approach to the ideal ballooning instability threshold at the periphery of the plasma. It is shown that the MHD ballooning parameter at the separatrix position alpha(sep) increases about linearly with the separatrix density normalized to Greenwald density, n(e,sep)/n(GW) for a wide range of discharge parameters in both devices. The observed operational space is found to reach at maximum n(e,sep)/n(GW) approximate to 0.4-0.5 at values for alpha(sep) approximate to 2-2.5, in the range of theoretical predictions for ballooning instability. This work supports the hypothesis that the H-mode density limit may be set by ballooning stability at the separatrix.