Pepsin is produced by the gastric acid from the inactive precursor pepsinogen, which is formed by the main cells of the stomach.