Why did the Buddha suffer before he died? I understand that the Buddha became severely ill prior to his death as a result of eating bad food. I also was under the impression that perfectly enlightened beings have obliterated, or rendered ineffective, all of their karma. If this is the case, why would the Buddha, the most perfectly enlightened of all, experience great suffering at the end of his life?
"I also was under the impression that perfectly enlightened beings have obliterated, or rendered ineffective, all of their karma"

The five skhandas are roughly understood as "past kamma". Even arahants experience the fruits of their past kamma and are only free of it in parinibbana. For example, there are suttas describing arahants being hurt. In the case of the Buddha specifically, there's a well known one where he had his foot hurt:


  I have heard that on one occasion the Blessed One was staying near Rajagaha at the Maddakucchi Deer Reserve. Now at that time his foot had been pierced by a stone sliver. Excruciating were the bodily feelings that developed within him — painful, fierce, sharp, wracking, repellent, disagreeable — but he endured them mindful, alert, &amp; unperturbed. Having had his outer robe folded in four and laid out, he lay down on his right side in the lion's posture, with one foot placed on top of the other, mindful &amp; alert.
  
  -- SN 1.38


"If this is the case, why would the Buddha, the most perfectly enlightened of all, experience great suffering at the end of his life?"

It's generally understood that he suffered body pain (at least when not in jhana). His own teaching carries this (like the quote above):


  "And what are the fermentations to be abandoned by tolerating? There is the case where a monk, reflecting appropriately, endures. He tolerates cold, heat, hunger, &amp; thirst; the touch of flies, mosquitoes, wind, sun, &amp; reptiles; ill-spoken, unwelcome words &amp; bodily feelings that, when they arise, are painful, racking, sharp, piercing, disagreeable, displeasing, &amp; menacing to life. The fermentations, vexation, or fever that would arise if he were not to tolerate these things do not arise for him when he tolerates them. These are called the fermentations to be abandoned by tolerating.
  
  -- MN 2


A well known sutta on this subject is the The Arrow which illustrates the differences between pain and suffering. Thus, pain could be understood as simply bodily discomfort (even if sharp), but unable to do anything beyond that, say, to his mind (which is naturally not the case for any "normal" person). However, like in the foot episode, he does appear managing these discomforts:


  Then the Blessed One — having spent most of the night instructing, urging, rousing, &amp; encouraging the Kapilavatthu Sakyans with a Dhamma talk — said to Ven. Ananda, "Ananda, speak to the Kapilavatthu Sakyans about the person who follows the practice for one in training. My back aches. I will rest it."
  
  -- MN 53


Finally, body pain (vedana in general) does not cease permanently with nibbana, if a body still has vitality.