Homer is diagnosed with clogged arteries and needs a triple bypass heart surgery. But the $40,000 price tag on the operation forces Homer to turn to Dr. Nick as a cheap alternative.
One night, while watching TV, Homer — shortly after Marge warns him against his unhealthy dietary habits (e.g. eating full meals right before bed, scarfing down several bags of chips and containers of dip at the same time ex.) — begins feeling chest pains, which return the next morning at breakfast. Marge prepares a "special surprise" for him for breakfast (oatmeal), Homer refuses to eat it, claiming that there was a bug in it. He eats a cholesterol-laden breakfast of eggs and bacon which 'really did' have a bug in it yet he still ate. While driving to work, Homer's chest pains worsen, but he chalks the irregular thumping to a problem with his car's transmission. The mechanic tells him it is probably his heart, and Homer, relieved the noise is not his car, drives away.
At work, Mr. Burns calls Homer in to reprimand him for his poor work performance, taunting him with dismissal all the while. Homer's chest pains get worse, and when he is told he is a terrible worker, he suffers heart attack. When Smithers tells Burns that Homer is dead, Burns asks him to send a ham to his widow; at that moment, after hearing the word "ham", Homer's soul returns to his body, regains consciousness and the ham is cancelled ("D'oh!").
Back at home, Marge gets a phone call from the hospital, telling her Homer has suffered a mild heart attack. When she quickly leaves, a visiting Patty and Selma continue cutting coupons, as though nothing is wrong.
Later, Dr. Hibbert, after using radiology to analyze his bloodstream and a fat jiggle test (to which the former implied that his bloodstream emits its own radiation, and the latter forced him to cancel his one o'clock appointment due to it taking a very long time to stop), advises Marge that Homer needs triple bypass, but Homer suffers another heart attack when he is told the price — $30,000 (which is subsequently upped to $40,000); no wonder — the Springfield Nuclear Power Plant doesn't offer health insurance, and the family has less than $100 in their savings account. Homer suffers a third heart attack at the health insurance office while signing up, and is denied because of his poor health. Upon being revived in the hospital, Homer tells Dr. Hibbert that he had a wonderful dream that he was in a place "filled with fire and brimstone, and that a bunch of people in red pajamas jabbed him in the butt with pitchforks."
Left without options and sure he'll die before he gets some much-needed surgery, Homer and Marge see a TV commercial for Dr. Nick Riviera, who performs bargain-basement surgery for $129.95. Despite Dr. Nick's obvious gross incompetence — thanks to not-too-subtle hints such as being called to the morgue (When a PA system announcer tells Dr. Nick over the intercom that the Coroner is waiting to see him, Dr. Nick sarcastically reacts, "The coroner? I'm so sick of that guy! See you in the operating place!" before being greeted by the media, closing the door, and saying."Oh, it's such a nice day. I think I'll go out the window." and jumping out of one-story window) — Homer sees the 'good' doctor as his only chance to have the surgery done an affordable price. While hospitalized, Homer, to his dismay, discovers Ned Flanders who is donating a kidney and a lung, is his roommate. However, in this time of need, Homer has become more of a praying man like Flanders, begging God to look after his family should God decide Homer's time has come. However, Homer is reprimanded by an angry nurse who reveals the hospital has a policy against prayer.
Just before the surgery, a nervous Dr. Nick tries to review the basic procedures of the surgery he is about to perform by renting an instructional video, but the most important part of the procedure is taped over with 'People Who Look like Things'. On the day of the surgery, Nick proceeds with the surgery but quickly realizes he doesn't know what to do. Fortunately, Lisa — who has studied cardiology — is in the operating room amphitheater and tells Dr. Nick that in order to begin the surgery he must cut below the blockage, and Dr. Nick seems to take it from there. Amazingly, the surgery is a success, and Homer makes a full recovery. His heart, with some help, thumps out the Simpson's theme tune in the end.