The primary function of Paneth cells is to secrete antimicrobial molecules to protect the gut from pathogenic bacteria. They release substances like lysozyme and alpha-defensins, which degrade bacterial cell walls and disrupt bacterial membranes, respectively. Additionally, Paneth cells help regulate the composition of the intestinal microbiota and support the function of stem cells in the crypts.