Aims. The goal of this work is to investigate Jupiter’s growth by focusing on the amount of heavy elements accreted by the planet, and to compare this with recent structure models of Jupiter.

Methods. Our model assumes an initial core growth dominated by pebble accretion, and a second growth phase that is characterised by a moderate accretion of both planetesimals and gas. The third phase is dominated by runaway gas accretion during which the planet becomes detached from the disc. The second and third phases were computed in detail, considering two different prescriptions for the planetesimal accretion and fits from hydrodynamical studies to compute the gas accretion in the detached phase.

Results. In order for Jupiter to consist of ~20–40 $M_{\oplus}$ of heavy elements as suggested by structure models, we find that Jupiter’s formation location is preferably at an orbital distance of $1 \leq a \leq 10$ au once the accretion of planetesimals dominates. We find that Jupiter could accrete between ~1 and ~15 $M_{\oplus}$ of heavy elements during runaway gas accretion, depending on the assumed initial surface density of planetesimals and the prescription used to estimate the heavy-element accretion during the final stage of the planetary formation. This would yield an envelope metallicity of ~0.5 to ~3 times solar. By computing the solid (heavy-element) accretion during the detached phase, we infer a planetary mass-metallicity ($M_P - M_Z$) relation of $M_Z \sim M_P\frac{2}{5}$, when a gap in the planetesimal disc is created, and of $M_Z \sim M_P\frac{1}{6}$ without a planetesimal gap.

Conclusions. Our hybrid pebble-planetesimal model can account for Jupiter’s bulk and atmospheric enrichment. The high bulk metallicity inferred for many giant exoplanets is difficult to explain from standard formation models. This might suggest a migration history for such highly enriched giant exoplanets and/or giant impacts after the disc’s dispersal.