There are two "M" terminals on the back of the ignition switch (if used) one of which is raised higher than all others.
The only wire to be attached to that "raised M" terminal is a "Black/Yellow" wire (the kill circuit.
The other regular "M" terminal should also have just one wire... a black wire running to ground...... Some boaters (many, really) and even boat yard riggers use this regular "M" terminal to attach and ground out their 12v power accessories (not a good idea). The problem this creates seems to vary on whether the boat is wood, fiberglass, or metal... no, I have no idea why.
However, in using that regular "M" terminal of the ignition switch for a ground and when the key is in the OFF position, both "M" terminals are connected... and if some accessory is turned on, the battery voltage cruising through that accessory is still DC voltage as it leaves its ground wire, and since the two "M" terminals are connected, that voltage has access to the magneto capacitance discharge ignition system... and in time, weird things will happen.
Sort of a poltergeist type thing! Perhaps not the cause of your problem, but it's something worth looking at.