Greek μηχανή — mēkhanē: instrument, device, contrivance, means.
Latin machina: machine, engine, apparatus, contrivance.
Middle French machine → English machine.
The semantic field is older and broader than today's image of gears, motors and electronics.