Escherichia coli (E. coli), a main mastitis-causing pathogen in sows, leads to mammary tissue damage. Here, we explored the effects of Lactobacillus johnsonii L531 on attenuating E. coli-induced inflammatory damage in porcine mammary epithelial cells (PMECs). L. johnsonii L531 pretreatment reduced E. coli adhesion to PMECs by competitive exclusion and the production of inhibitory factors and decreased E. coli-induced destruction of cellular morphology and ultrastructure. E. coli induced activation of NLRP3 inflammasome associated with increased expression of NLRP3, ASC, and cleaved caspase-1, however, L. johnsonii L531 inhibited E. coli-induced activation of NLRP3 inflammasome. Up-regulation of interleukin (Il)-1β, Il-6, Il-8, Il-18, tumor necrosis factor alpha, and chemokine Cxcl2 expression after E. coli infection was attenuated by L. johnsonii L531. E. coli infection inhibited autophagy, whereas L. johnsonii L531 reversed the inhibitory effect of E. coli on autophagy by decreasing the expression of autophagic receptor SQSTM1/p62 and increasing the expression of autophagy-related proteins ATG5, ATG16L1, and light chain 3 protein by Western blotting analysis. Our findings suggest that L. johnsonii L531 pretreatment restricts NLRP3 inflammasome activity and induces autophagy through promoting ATG5/ATG16L1-mediated autophagy, thereby protecting against E. coli-induced inflammation and cell damage in PMECs.