Résumé : Context. S stars are transition objects between M-type giants and carbon stars on the asymptotic giant branch (AGB). They are characterized by overabundances of s-process elements. Roughly half of them are enhanced in technetium (Tc), an s-process element with no stable isotope, while the other half lack technetium. This dichotomy arises from the fact that Tc-rich S stars are intrinsically producing s-process elements and have undergone third dredge-up (TDU) events, while Tc-poor S stars owe their s-process overabundances to a past pollution by a former AGB companion which is now an undetected white dwarf, and since the epoch of the mass transfer, technetium has totally decayed. Aims. Our aim is to analyse the abundances of S stars and gain insights into their evolutionary status and on the nucleosynthesis of heavy s-process elements taking place in their interior. In particular, the location of extrinsic and intrinsic S stars in the HR diagram will be compared with the theoretical onset of the TDU on the thermally pulsing AGB. Methods. A sample of 19 S-type stars was analysed by combining HERMES high-resolution spectra, accurate Gaia Data Release 2 (GDR2) parallaxes, stellar-evolution models, and newly designed MARCS model atmospheres for S-type stars. Various stellar parameters impact the atmospheric structure of S stars, not only effective temperature, gravity, metallicity and microturbulence but also C/O and [s/Fe]. We show that photometric data alone are not sufficient to disentangle these parameters. We present a new automatic spectral-fitting method that allows one to constrain the range of possible atmospheric parameters. Results. Combining the derived parameters with GDR2 parallaxes allows a joint analysis of the location of the stars in the Hertzsprung-Russell diagram and of their surface abundances. For all 19 stars, Zr and Nb abundances are derived, complemented by abundances of other s-process elements for the three Tc-rich S stars. These abundances agree within the uncertainties with nucleosynthesis predictions for stars of corresponding mass, metallicity and evolutionary stage. The Tc dichotomy between extrinsic and intrinsic S stars is seen as well in the Nb abundances: Intrinsic, Tc-rich S stars are Nb-poor, whereas extrinsic, Tc-poor S stars are Nb-rich. Most extrinsic S stars lie close to the tip of the red giant branch (RGB), and a few are located along the early AGB. All appear to be the cooler analogues of barium stars. Barium stars with masses smaller than 2.5 M⊙ turn into extrinsic S stars on the RGB, because only for those masses does the RGB tip extend to temperatures lower than ∼4200 K, which allows the ZrO bands distinctive of S-type stars to develop. On the contrary, barium stars with masses in excess of ∼2.5 M⊙ can only turn into extrinsic S stars on the E-AGB, but those are short-lived, and thus rare. The location of intrinsic S stars in the HR diagram is compatible with them being thermally-pulsing AGB stars. Although nucleosynthetic model predictions give a satisfactory distribution of s-process elements, fitting at the same time the carbon and heavy s-element enrichments still remains difficult. Finally, the Tc-rich star V915 Aql is challenging as it points at the occurrence of TDU episodes in stars with masses as low as M ∼ 1 M⊙