This began as a Japanese game with a name that was something like Doki Doki Panic, though I'm probably remembering it wrong. It had nothing to do with Mario. This is evident from the completely different enemies and the little Japanese people who cheer for you in the ending sequence.

Incidentally, I just replayed this game (or at least the Super Mario All-Stars remake of it). For one thing, it was much harder than I remember it being. And I now agree that it is definitely the most fun of the NES Mario games, and the most unpredictable of any of them including the Super Mario World ones.

Some of the level designs were completely ingenious, and some were more to the evil side. One rather cool level was level 3-2, because it wasn't shaped like any other level - you went back and forth along three long areas that were stacked above each other, one above the ground, one under the ground on the same screen, and one on the screen below. You had to cross between these at the right places.

An evil level was level 5-1, where you had to hop across large expanses of water on jumping fish.

The final castle, level 7-2, was a combination of cool and evil - there were two tracks through the castle, one hard one where you got a mushroom and an easier one where you didn't; of course they led into each other, so if you didn't know what to do when you reached the big room where they met, you would end up going backwards along the other one and smacking yourself as you ended up back where you started. Getting out of there involved the deceptively simple-looking task of defeating a Birdo and bringing a key across a short conveyor-belt; however, the evil mask dude would instantly follow you, and he can fly over the conveyor belt and you can't. And the finishing touch was how the exit door would fly off the wall and attack you in the end.