Vasoactive intestinal peptide (VIP), a member of secretin/glucagon family, is involved in a variety of biological activities such as gut motility, immune responses, and carcinogenesis. In this study, the VIP precursor gene (On-VIP) and its receptor gene VIPR1 (On-VIPR1) were identified from Nile tilapia (Oreochromis niloticus), and the functions of On-VIP in the immunomodulation of Nile tilapia against bacterial infection were investigated and characterized. On-VIP and On-VIPR1 contain a 450 bp and a 1326 bp open reading frame encoding deduced protein of 149 and 441 amino acids, respectively. Simultaneously, the transcript of both On-VIP and On-VIPR1 were highly expressed in the intestine and sharply induced by Streptococcus agalatiae. Moreover, the positive signals of On-VIP and On-VIPR1 were detected in the longitudinal muscle layer and mucosal epithelium of intestine, respectively. Furthermore, both in vitro and in vivo experiments indicated several immune functions of On-VIP, including reduction of P65, P38, MyD88, STAT3, and AP1, upregulation of CREB and CBP, and suppression of inflammation. Additionally, in vivo experiments proved that On-VIP could protect Nile tilapia from bacterial infection and promote apoptosis and pyroptosis. These data lay a theoretical basis for further understanding of the mechanism of VIP guarding bony fish against bacterial infection.