Cardiac rehabilitation helps patients recover after a heart attack by improving heart function through supervised exercise, dietary changes, and education. It also helps patients adopt heart-healthy habits that reduce the risk of another myocardial infarction.