Ignition switch may be loose, and not grounding out the engine.
Check to make sure the switch is tight to the dash.
Or switch could be going bad.
In engine wouldn't likely diesel for that long (20 sec).
This is common. Used to happen on my 17hp Briggs Intek powered MTD pile-o-poop. It's the same situation as the "afterfire" or backfire upon s/d you get on some of today's hot running EPA carb'd equipment. The last sip of fuel from the carb gets sucked into the hot combustion chamber and either causes 'dieseling'or a ka-POW!! out the exhaust. The only way to prevent it is kill the ignition at hi RPM or blip the throttle up just after you kill the ignition. This leans the a/f ratio just enough to prevent what you've experienced.