It is now well established that globular clusters (GCs) exhibit star-to-star light-element abundance variations (known as multiple stellar populations, MPs). Such chemical anomalies have been found in (nearly) all the ancient GCs (more than 10 Gyr old) of our Galaxy and its close companions, but so far no model for the origin of MPs is able to reproduce all the relevant observations. To gain new insights into this phenomenon, we have undertaken a photometric Hubble Space Telescope survey to study clusters with masses comparable to that of old GCs, where MPs have been identified, but with significantly younger ages. Nine clusters in the Magellanic Clouds with ages between $sim$ 1.5-11 Gyr have been targeted in this survey. We confirm the presence of multiple populations in all clusters older than 6 Gyr and we add NGC 1978 to the group of clusters for which MPs have been identified. With an age of $sim$ 2 Gyr, NGC 1978 is the youngest cluster known to host chemical abundance spreads found to date. We do not detect evident star-to-star variations for slightly younger massive clusters ($sim$ 1.7 Gyr), thus pointing towards an unexpected age dependence for the onset of multiple populations. This discovery suggests that the formation of MPs is not restricted to the early Universe and that GCs and young massive clusters share common formation and evolutionary processes.