Some vegetables contain iron, selenium, magnesium, and other minerals that conduct electricity. Microwaves have electric and magnetic fields, and minerals within the vegetables act as antennae for the electric fields.
When there’s a difference between the electrical properties between two bits of material—say, the surface of one piece of kale and the surface of another nearby piece—it creates an arc of electricity, which we see as a spark. The electrical charge moves from the material with high electrical potential to a surface with a lower electrical potential. Metal utensils and compact discs spark up for the same reason, although with those materials, the phenomena is much more destructive (since there’s a larger amount of conductive metal).
Let’s get back to the electrified veggies. Are they safe to eat?
Yes, but you shouldn’t cook food this way. If the food in question is dry enough, it can catch on fire. This rarely happens with vegetables; in most cases, the food will simply crisp up, and the microwave might shut off automatically to protect its magnetron tube.
Vegetables are more likely to catch on fire if they’re not smooth—crinkly kale, for instance—and salt might help to cause the reaction, as it changes the electric potential of the materials. As NPR notes, kale, green beans, bell peppers, and carrots have especially high mineral content and are more likely to spark. However, sauces and soups that contain these elements probably won’t—the liquid basically puts out the spark before it has a chance to, uh, spark.
Microwaves rarely burn down from vegetable fires, but while this is a fun effect to explore, be aware that it can eventually damage your oven. Turn off your microwave as soon as you see sparks (and consider sautéeing your spinach next time).