deus ex machina (n.)

1690s, from Modern Latin translation of Greek apo mekhanes theos, literally "the god from the machina," the device by which "gods" were suspended over the stage in Greek theater, from Greek (Attic) mekhane "device," from PIE *magh-ana- "that which enables," from root *magh- "to be able, have power." The fem. is dea ex machina.