I've had several microwaves that have had various issues over the years, and in most cases I've found that they can usually be traced down to the door switches. There are generally two or three door switches, and they most often have ones that tell the microwave the door is open and others that tell the microwave the door is closed.
These prevent power from being applied when the door is open and ensure it's closed. When one or more of them isn't working, the microwave can get into a state it's not expecting and can energize circuits at the wrong time, causing all kinds of problems, including ones similar to yours.
The door switches are generally fairly easy to check and fix, so that's pretty much where I always start in diagnosing the problem on any given microwave. So far I've only run into one case where the door switches weren't the problem, so I'd suggest taking a look at those first.
You'll need an ohmmeter or continuity tester to verify the proper operation of the switches; I've had some that sounded like they were clicking and working, but electrically they weren't functioning as verified by my ohmmeter. The switches come in two flavors; normally open and normally closed; the position of one of the electrical contacts is what differentiates them. You can buy ones that support both operations so you don't have to buy two separate parts; those will cover either case; it's just a matter of where you plug in the wire that determines which operation it's going to perform.
The door switches aren't a particularly dangerous part of the microwave to work on as long as it's unplugged from the AC power, but otherwise you do need to heed @jayeff's warnings about working inside a microwave oven.
Good luck; let us know what you find.