To do this, once you lose and have lost all turns for Mario or Luigi or both, hold A+B and then press Start at the Game Over screen.
If you touch the end flagpole with a 1,3, or 6 in the ones column (example 091, 243, or 256) you will get fireworks equal to that number (1,3, or 6) and 500 points for each.
After completing the game once you can actually choose what level to go to on the title screen. Press B to change the level number the demo is playing on.
To reach this area, stand on the pipe in World 1-2 that takes you to the flagpole. Break the 2nd and 3rd blocks from the right. Then, face left and jump. Hit the back of your head on the left side of the brick next to the pipe. If you do it right, you should be pulled through the wall. Quickly jump into the left pipe to enter the Minus World. It consists of three levels (going to -3) where you can beat the game.
This glitch only works in the castle levels where you fight Bowser at the end - for example, World 1-4, 2-4, 3-4, and so on. It is best to defeat Bowser with Fire Mario or Fire Luigi beforehand, as you must wait out most of the timer to execute this glitch. At the end of the castle levels, there is an axe which you must touch to end the level. If you time your jump correctly (a full jump as the timer goes from 002 to 001 often works) and land on the axe while the timer reads "000", you'll continue as normal to the usual sequence at the end of the castle. However, your timer bonus (50 points per second remaining) will be calculated as if you had 999 seconds, not zero, left on the clock. This allows for an easy 49,950 point boost! Note that this glitch, if executed on levels using a flagpole, will prevent you from earning the bonus in that level.