Bart Simpson did not originate the Spanish expression - but Bart, being Bart, probably knew the origin. It goes back to 1835 at least and is an expression of surprise at some unpleasant incident or news, e.g seeing a spider in the bathtub, or hearing bad news about someone's health - 'Ay caramba, that's serious!' The word "caramba" is a euphemism for "'carajo" (penis). I read that (appropriately, perhaps,) Ay, caramba!" were also Bart's first words when he saw his parents having sex.