The story
Possibly from the reported practice of soldiers biting a bullet to avoid crying out in pain, usually during a medical procedure or punishment. See the Wikipedia article Bite the bullet for a further discussion of possible etymologies.
Etymology from Wiktionary, CC BY-SA 4.0.