2D:
Super Mario Bros. 3: This, in my opinion, was when Mario games went from "good" to "legendary". The original SMB may have been incredibly influential, but it was also simplistic, repetitive, and if we're being totally honest with ourselves, quite boring actually. SMB2 improved greatly over SMB in many ways, but also took some step sideways and backwards too.
SBM3, however, took everything good about SMB, turbocharged it, and added a whole slew of new features and challenges, a massive variety of themed worlds and new powerups, and essentially set the template for all future Mario platformers.
Super Mario World: Basically like SMB3, but with better controls, more of a focus on exploration, larger levels, and the ability to replay levels, which we honestly take for granted nowadays. From just a functionality perspective, this is probably my favorite 2D Mario, just bareley eeking out SMB3.
Honorable mentions: NSMBW, NSMBU
3D:
Super Mario Galaxy: This game is virtually the perfect Mario game I imagined in my head for many years. It does practically everything that I wanted in a Mario game. Brilliant platforming, numerous themed levels, a brilliant central mechanic, excellent level design, gorgeous graphics, a killer soundtrack, and just all around excellence. My three only real complaints are that 1) it would have been nice if the power ups were permanent instead of temporary 2) there were more sandbox type levels 3) if the moveset and controls were a bit deeper like SM64 and Sunshine. But in the grand scheme of things, these are nitpicks at best.
Super Mario Galaxy 2: Basically like SMG, but with better level design. So why is this no. 2? Because although SMG2 is excellent and arguably better in terms of gameplay, one of the great things about SMG was the novelty factor. Sure, SMG2 is wonderful, but it's also pretty much an expansion pack, which is why to this day I'm surprised gaf hasn't ripped it to shreds like it would any other game that attempted such a thing *cough* Zelda *cough*. But regardless, it's amazing.
Honorable mentions: SM64, SMS