It is largely accepted that Galactic cosmic rays, which pervade the interstellar medium, originate by means of shock waves in supernova remnants. Cosmic rays activate the rich chemistry that is observed in a molecular cloud and they also regulate its collapse timescale, determining the efficiency of star and planet formation, but they cannot penetrate up to the densest part of a molecular cloud, where the formation of stars is expected, because of energy loss processes and magnetic field deflections. Recently, observations towards young protostellar systems showed a surprisingly high value of the ionisation rate, the main indicator of the presence of cosmic rays in molecular cloud. Synchrotron emission, the typical feature of relativistic electrons, has also been detected towards the bow shock of a T Tauri star. Nevertheless, the origin of these signatures peculiar to accelerated particles is still puzzling. Here we show that particle acceleration can be driven by shock waves occurring in protostars through the first-order Fermi acceleration mechanism. We expect that shocks in protostellar jets can be efficient accelerators of protons, which can be boosted up to mildly relativistic energies. A strong acceleration can also take place at the protostellar surface, where shocks produced by infalling material during the phase of collapse are powerful enough to accelerate protons. Our model shows that thermal particles can experience an acceleration during the first phases of a system similar to the proto-Sun, and can also be used to explain recent observations. The presence of a local source of cosmic rays may have an unexpected impact over the process of the formation of stars and planets, as well as on the pre-biotic molecule formation.