Major abdominal procedures could induce dysfunction in the immune system and lead to postoperative immunosuppression. Sleep dysfunction is associated with impaired immune activity. However, the effects of postoperative sleep dysfunction on postoperative immune function remain unclear. In this study, we found that sleep-restriction (SR) after surgery increased the spleen weight and the percentage of myeloid-derived suppressor cells (MDSCs) in the spleen, and inhibited splenic CD8+ T cells activity, which was via inhibiting subdiaphragmatic vagus nerve (SVN)-mediated trefoil factor 2 (TFF2) expression in the spleen of aged mice. Dexmedetomidine could alleviate SR-induced these changes via modulating gut microbiota, which acted through SVN. Moreover, we showed essential roles of splenic TFF2 in attenuating SR-induced reduced protective ability against Escherichia coli (E. coli) pneumonia, increased expression of IL-4 and IL-13 in the lung and M2 polarization of alveolar macrophages (AMs), and decreased phagocytic activity of AMs. Dexmedetomidine improved SR-induced reduced protective ability against E. coli pneumonia via splenic TFF2, and subsequently decreasing IL-4 and IL-13 expression in the lung via modulating gut microbiota/SVN, increasing the compromised phagocytic activity of AMs, and ultimately decreasing M2 polarization of AMs. Taken together, dexmedetomidine-induced increase in splenic TFF2 expresssion could alleviate SR-induced exaggeration of postoperative immunosuppression.