Egad is a morphed form of
egads.
Egads used to mean "
ye gods" and now is more closely linked to "OMG" or "oh god"; Some people think there is only one god, so
egad has evolved to express that idea. At the heart of it is the notion that god is a trickster who screws with us.
We use it to say that something severely messed up has just happened.