Bernie Sanders acknowledged on Wednesday that he knew he had suffered a heart attack three days before his campaign released that information, but he defended the decision to keep those details private.

Mr. Sanders’s campaign had been inundated with questions from the news media last week as he recovered at a hospital in Las Vegas, and speculation about whether he had had a heart attack spread on social media and among voters. Campaign officials waited until Mr. Sanders was released from the hospital on Friday, smiling and waving to news reporters, before disclosing that he had.

In an interview with NBC News, Mr. Sanders said a doctor at an urgent care facility in Las Vegas, where he went last Tuesday night after experiencing chest pain, had informed him that he was having a “heart event.” The interviewer then asked if the doctor had said he was having a heart attack, to which Mr. Sanders said, “Yeah.”

His campaign did not announce that until Friday, saying only that doctors had inserted two stents to open a blocked artery — a fairly common procedure. A heart attack, known medically as a myocardial infarction, means that there was at least some damage to the heart muscle.