Streptococcus agalactiae (Group B Streptococcus, GBS) is a severe pathogen that has resulted in enormous economic losses in the global tilapia sector. GBS can be effectively controlled by antibiotics to some extent, but antibiotic resistance limits the application of antibiotics. It is urgent to find eco-friendly novel strategies against GBS. As the smallest antibody, nanobodies (Nbs) are novel effective biologics for treating bacterial and viral infections, as they can identify conserved epitopes of hypervariable pathogens. In the study, GBS-specific Nbs were screened from a naive phage-displayed Nb library, and the anti-GBS activity of Nbs was explored in vivo. The results showed that high-affinity Nbs were obtained from a naive phage-displayed Nb library after three rounds of biopanning. A novel nanobody Nb01 was expressed in the Escherichia coli expression system and purified using the Ni-NTA Agarose column. The results of indirect ELISA showed that purified recombinant protein Nb01 still had a high affinity against GBS. Furthermore, we found that Nb01 could effectively inhibit GBS infection in vivo. The copy numbers of GBS in the zebrafish brains were significantly reduced after treatment with Nb01. The survival rate of GBS-infected zebrafish treated with Nb01 was 70.0%, while it was only 43.3% for the controls. The expression of proinflammatory cytokine genes (tnf-α, il-6 and inf-γ) and Wnt-signaling related genes (wnt2, wnt3a and fzd5) in the GBS-infected zebrafish brain were significantly decreased after treatment with Nb01. In conclusion, Nb01 could protect zebrafish from GBS infection, and these results highlighted the potential therapeutic activity of Nbs against GBS in fish.