Highly pathogenic avian influenza (HPAI) clade 2.3.4.4b H5N1 virus has recently emerged in dairy cattle in the USA, leading to mastitis and sharp reductions in milk production. The main site of H5N1 viral replication is the mammary tissue rather than the respiratory tract and viral transmission between animals is thought to occur through viral shedding in milk. Here, we generate an mRNA–lipid nanoparticle (mRNA–LNP) vaccine encoding the hemagglutinin (HA) of A/dairy cattle/Texas/24-008749-002/2024, representative of circulating bovine H5N1 viruses, and assess its immunogenicity and efficacy in lactating dairy cows. Eight cows were divided into vaccinated and control groups, receiving two intramuscular doses of the vaccine or saline, followed by intramammary viral challenge. Vaccination elicited HA-reactive and neutralizing antibodies in serum and HA-reactive antibodies in milk. Following viral challenge, vaccinated cows had ~1,000-fold lower peak viral RNA in milk and a lower occurrence of mastitis and mammary fibrosis.