Periprosthetic infections caused by Staphylococcus aureus (S. aureus) pose unique challenges in orthopedic surgeries, in part due to the bacterium's capacity to invade surrounding bone tissues besides forming recalcitrant biofilms on implant surfaces. We previously developed prophylactic implant coatings for the on-demand release of vancomycin, triggered by the cleavage of an oligonucleotide (Oligo) linker by micrococcal nuclease (MN) secreted by the Gram-positive bacterium, to eradicate S. aureus surrounding the implant in vitro and in vivo. Building upon this coating platform, here we explore the feasibility of extending the ondemand release to ampicillin, a broad-spectrum aminopenicillin β-lactam antibiotic that is more effective than vancomycin in killing Gram-negative bacteria that may accompany S. aureus infections. The amino group of ampicillin was successfully conjugated to the carboxyl end of an MN-sensitive Oligo covalently integrated in a polymethacrylate hydrogel coating applied to titanium alloy pins. The resultant Oligo-Ampicillin hydrogel coating released the β-lactam in the presence of S. aureus and successfully cleared nearby S. aureus in vitro. When the Oligo-Ampicillin-coated pin was delivered to a rat femoral canal inoculated with 1000 cfu S. aureus, it prevented periprosthetic infection with timely on-demand drug release. The clearance of the bacteria from the pin surface as well as surrounding tissue persisted over 3 months, with no local or systemic toxicity observed with the coating. The negatively charged Oligo fragment attached to ampicillin upon cleavage from the coating did diminish the antibiotic's potency against S. aureus and Escherichia coli (E. coli) to varying degrees, likely due to electrostatic repulsion by the anionic surfaces of the bacteria. Although the on-demand release of the β-lactam led to adequate killing of S. aureus but not E. coli in the presence of a mixture of the bacteria, strong inhibition of the colonization of the remaining E. coli on hydrogel coating was observed. These findings will inspire considerations of alternative broad-spectrum antibiotics, optimized drug conjugation, and Oligo linker engineering for more effective protection against polymicrobial periprosthetic infections.