A method of treating or preventing a bacterial infection in an animal comprises administering to the animal an effective amount of an antibacterial peptide, the antibacterial peptide being derived from degraded date pits which are degraded by solid state degradation by a fungus, Trichoderma reesei. The antibacterial peptide has a molecular mass of less than 10 kDa and an amino acid sequence including (a) SEQ ID NO:4 or (b) SEQ ID NO:6. The bacterial infection is caused by a Gram-positive bacteria or a Gram-negative bacteria, for example, a Salmonella species, a Campylobacter species, a Shigella species, an Escherichia species, a Pseudomonas species, and a Staphylococcus species.