Penicillins act by inhibiting the enzyme transpeptidase, which is essential for the cross-linking of peptidoglycan chains in bacterial cell walls. This inhibition weakens the cell wall, leading to cell lysis and death of the bacteria. By targeting bacterial cell walls, penicillins are effective against Gram-positive bacteria and some Gram-negative bacteria.