Nanofibers are potential vaccines or adjuvants for vaccination at the mucosal interface. However, how their lengths affect the mucosal immunity is not well understood. Using length-tunable flagella (self-assembled from a protein termed flagellin) as model protein nanofibers, we studied the mechanisms of their interaction with mucosal interface to induce immune responses length-dependently. Briefly, through tuning flagellin assembly, length-controlled protein nanofibers were prepared. The shorter nanofibers exhibited more pronounced toll-like receptor 5 (TLR5) and inflammasomes activation accompanied by pyroptosis, as a result of cellular uptake, lysosomal damage, and mitochondrial reactive oxygen species generation. Accordingly, the shorter nanofibers elevated the IgA level in mucosal secretions and enhanced the serum IgG level in ovalbumin-based intranasal vaccinations. These mucosal and systematic antibody responses were correlated with the mucus penetration capacity of the nanofibers. Intranasal administration of vaccines (human papillomavirus type 16 peptides) adjuvanted with shorter nanofibers significantly elicited cytotoxic T lymphocyte responses, strongly inhibiting tumor growth and improving survival rates in a TC-1 cervical cancer model. This work suggests that length-dependent immune responses of nanofibers can be elucidated for designing nanofibrous vaccines and adjuvants for both infectious diseases and cancer.