Nuclear factor Y (NF-Y) is a heterotrimeric transcription factor that plays an important role in various biological processes in plants, such as flowering regulation, drought resistance, and salt stress. However, few in-depth studies investigated the alfalfa NF-Y gene family. In this study, in total, 60 MsNF-Y genes, including 9 MsNF-YAs, 26 MsNF-YBs, and 25 MsNF-YCs, were identified in the alfalfa genome. The genomic locations, gene structures, protein molecular weights, conserved domains, phylogenetic relationships, and gene expression patterns in different tissues and under different stresses (cold stress, drought stress, and salt stress) of these NF-Y genes were analyzed. The illustration of the conserved domains and specific domains of the different subfamilies of the MsNF-Y genes implicates the conservation and diversity of their functions in alfalfa growth, development, and stress resistance. The gene expression analysis showed that 48 MsNF-Y genes (7 MsNF-YAs, 22 MsNF-YBs, and 19 MsNF-YCs) were expressed in all tissues at different expression levels, indicating that these genes have tissue expression specificity and different biological functions. In total, seven, seven, six, and eight MsNF-Y genes responded to cold stress, the ABA treatment, drought stress, and salt stress in alfalfa, respectively. According to the WGCNA, molecular regulatory networks related to salt stress were constructed for MsNF-YB2, MsNF-YB5, MsNF-YB7, MsNF-YB15, MsNF-YC5, and MsNF-YC6. This study could provide valuable information for further elucidating the biological functions of MsNF-Ys and improving salt tolerance and other abiotic stress resistance in alfalfa.