John Quinn, a retired newspaper editor, likes to wear the teal cotton T-shirt he got from the 2012 Broad Street Run, a 10-mile race in Philadelphia. It was his first 10-mile event, and he’d come a long way to get to that 2012 starting line: losing more than 60 pounds and going from calling himself “John 316,” a reference to his previous weight, to being a dedicated runner.

But less than four years later, in 2015, Mr. Quinn, now 64, had a heart attack from a complete, sudden blockage of his right coronary artery. That led to part of his heart dying and a tear in the muscle bridge that separates the left and right ventricles.

If that all sounds bad, it was. Repairing that bridge is a delicate procedure, and about 50 percent of patients die within 30 days after the operation, according to Dr. Matthew L. Williams, assistant professor of cardiac surgery at Presbyterian Medical Center of Philadelphia and Mr. Quinn’s surgeon.

Mr. Quinn spent 53 days in the hospital. He pulled through it, and then had a follow-up surgery to implant a pacemaker.

Once, someone like Mr. Quinn would have been ordered to remain in bed for months after his heart attack. “Things have changed a lot from the Eisenhower era of bed rest,” said Dr. R. Kannan Mutharasan, a cardiologist at Northwestern Memorial Hospital in Chicago. Back then, patients were told to lie in bed and were even given “stool softeners so people didn’t have to strain,” he said.

“In the long run, we know that engaging in running and other cardiovascular activities prevents heart attacks,” said Dr. Mutharasan. Something like running helps the heart use oxygen more efficiently and regrow blood vessels.

“The principle ‘move it or lose it’ applies,” he said. “We don’t want to turn people into what we called ‘cardiac cripples.’”

Cardiac rehabilitation is typically three days a week for 12 weeks, starting about two weeks after the heart attack, said Dr. Mutharasan. Patients will get on a treadmill or a bike with a nurse while the heart is monitored.

“It helps people know their parameters. It helps people get back into exercise,” he said. “It helps people feel comfortable that they can do these things — not just physical limitations, but to understand the psychological concerns about getting back into physical exercise.”

Since cardiac rehab is typically done in a group setting, it also helps patients meet other people “who have similar conditions and concerns and to know they’re not alone,” he said.

Dr. Williams, Mr. Quinn’s surgeon, said that Mr. Quinn’s fitness leading into his illness “probably gave him more reserve to withstand all of the trauma from the illness and the surgery,” he said. He added that it also “probably helped his mental toughness, because there are a lot of psychological challenges to being that sick and to recover from it.”

“You can get healthier from running, but it doesn’t negate the need to deal with other risk factors someone might have. It doesn’t confer perfect protection,” Dr. Mutharasan said.

Indeed, most runners know the name Jim Fixx, the author of “The Complete Guide to Running,” which in 1977 helped kick off the first running boom. Mr. Fixx died of a heart attack while running in 1984.

Matthew Friedman, 60, a rabbi and senior transportation planner for the California Department of Transportation, ran a 21-mile training run the day before he had what is commonly referred to as a “widow maker” heart attack. His wife performed CPR on him until he could get to a hospital, where doctors found he had a 90 percent blockage in the left anterior descending artery.

“The doctors were baffled: Why would a 59-year-old guy who runs marathons and never smoked have a heart attack?” said Mr. Friedman.The answer: genetics. Both his father and grandfather suffered from heart disease.

When and how much to run after a heart attack depends on the person and the severity of the event.

Mr. Quinn was in the hospital for 53 days and didn’t run a race again until more than two years after his heart attack. He still struggles with neuropathy from the anesthesia he received in the hospital.

Mr. Friedman, who had his heart attack last September, left the hospital the next month. He ran the Mountains 2 Beach Marathon in California on May 27 of this year.

“It reminds me a little bit of hiking Mt. Washington,” Mr. Quinn said of coming back from being inert in the I.C.U. “You get past the tree line and look up at what you think is the top, but after a half-hour of hiking, it still looks that far away. But once you get to the top, wow what a view.”