The same forces that cause the ejecta of a firearm (the projectile(s), propellant gas, wad, sabot, etc.) to move down the barrel also cause all or a portion of the firearm to move in the opposite direction.
Since there is a minimum momentum required to operate a recoil-operated firearm's action, the cartridge must generate sufficient recoil to provide that momentum.