If your microwave runs for a few seconds and then stops then following must have gone wrong inside it:
Faulty door switches
There are door switches in a microwave which must be sealed tightly for the microwave to operate properly. If the microwave runs for a few seconds and then shuts off, the door switch might be defective or loose. Sometimes arching or overheating of door switches stops microwave from running efficiently. Some microwaves have a seal or gasket around the door. If the seal or gasket is broken, microwave shuts down. If your microwave is giving you such trouble call a professional for microwave repair.
Defective touch-pad or control panel
Some microwave models have knobs and dials while others have touch-pads. Microwaves with touch-pads are technological advanced but sensitive compared to the ones with knobs. So if your microwave stops suddenly then there might be a short in the touch-pad control panel.
Malfunctioning voltage transformer
There is a high voltage transformer in a microwave that produces high voltage to charge the magnetron. Upon charging the magnetron emits radio-waves which travels through the wave guide and enter the food area to cook or heat your food. If the microwave runs for a few seconds and stops, the high voltage transformer might have got a sudden short in its circuit. Call a professional for microwave repair.
Faulty cooling fan
There is a fan inside microwave that runs to keep magnetron and other circuitry items cool. So if the microwave starts but the fan does not turn on, it may stop automatically for safety reason.
Microwave also has an air vent to keep it cool. If this vent gets clogged with grease and dust, the microwave will not operate properly. Microwave will shut down automatically for safety reason. So clean the vent with a brush to prevent this problem.
Other reasons that may cause your microwave to shut down immediately are burned internal fuse or defective diodes or faulty capacitors. Call a professional to diagnose and fix the problem of microwave not working.
(Cover image source: www.learn.compactappliance.com)