When Mario gets a star he will become invincible for a short time and you'll hear the Invincible BGM tune. During this time you are immune to all enemies, and the only thing that can kill you is falling off the screen.
The title comes from the Famicom 20th Anniversary Original Sound Tracks Vol.1 album.
Super Mario Bros. (NES)
This song plays very rapidly, and sounds really crazy when you're running out of time. Both versions of the song loop.
Super Mario Bros. 2 (NES)
Koji Kondo remixed the Invincible music for Super Mario Bros. 2 with a nice percussion on the PCM channel.
The game's official soundtrack uses the title "無敵 (Muteki)" which means "Invincible," but doesn't use the BGM suffix.
The song is track 5 in the NSF file.