Allogeneic mesenchymal stem cells (MSCs) were immunoprivileged early after cardiac implantation and improved heart function in preclinical and clinical studies. However, long-term preclinical studies demonstrated that allogeneic MSCs lost their immunoprivilege and were rejected in the injured myocardium, resulting in recurrent ventricular dysfunction. This study identifies some of the mechanisms responsible for the immune switch in MSCs and suggests a new treatment to maintain immunoprivilege and preserve heart function. Rat MSC immunoprivilege was mediated by prostaglandin E2 (PGE2)-induced secretion of 2 critical chemokines, CCL12 and CCL5. These chemokines stimulated the chemoattraction of T cells toward MSCs, suppressed cytotoxic T-cell proliferation, and induced the production of T regulatory cells. MSCs treated with 5-azacytidine for 24 hours differentiated into myogenic cells after 2 weeks, which was associated with decreased PGE2 and chemokine production and the loss of immunoprivilege. Treatment of differentiated MSCs with PGE2 restored chemokine levels and preserved MSC immunoprivilege. In a rat myocardial infarction model, allogeneic MSCs (3 × 10(6) cells/rat) were injected into the infarct region with or without a biodegradable hydrogel that slowly released PGE2. Five weeks later, the transplanted MSCs expressed myogenic lineage markers and were rejected in the control group, but in the PGE2-treated group, the transplanted cells survived and heart function improved. Allogeneic MSCs maintained immunoprivilege by PGE2-induced secretion of chemokines CCL12 and CCL5. Differentiation of MSCs decreased PGE2 levels, and immunoprivilege was lost. Maintaining PGE2 levels preserved immunoprivilege after differentiation, prevented rejection of implanted MSCs, and restored cardiac function.