Penicillin works by inhibiting the synthesis of bacterial cell walls, which leads to the lysis and death of the bacteria. It targets the peptidoglycan layer crucial for bacterial cell wall strength and integrity, making it highly effective against actively growing bacteria.