First-order Fermi acceleration in solar flares as a mechanism for the second-step acceleration of prompt protons and relativistic electrons