From the Super Mario Wiki
The Enemy Course is a battle course found in all worlds, except for World 9, from New Super Mario Bros. Wii. It is similar to the Hammer Bro. battles from Super Mario Bros. 3, even sporting a remix of the Hammer Bros. theme. The player needs to collect eight Toad Balloons, while enemies attack them, to release a treasure chest that contains a Toad in it. Once all balloons are collected, the Toad thanks the player for rescuing him and will give the player three Super Mushrooms. This course is played at some points of the Map where an enemy is found. In Worlds 6 and 8, the player can do their Enemy Course infinite times. The enemies do not need to be defeated. However, the enemies are automatically defeated when the game is won. The players cannot quit these courses so in order to get back to the World Map the player has to complete the course or lose a life however if the player loses a life, they will be knocked back to the space where they were on the World Map.
Losing a life in any level will cause enemies to reappear on the map. Using a Star when on the map and running into one of the enemies will immediately dispatch them without having to enter these courses, but the player will not receive three Super Mushrooms for doing so.
While being absent in New Super Mario Bros. 2, enemy Courses return in New Super Mario Bros. U, there are 7 Enemy Courses this time around. Unlike the courses in New Super Mario Bros. Wii, the enemies must be defeated in order to retrieve the prize, which is a Starman this time around instead of three Super Mushrooms handed by Toad, but if the player doesn't open the chest for a long moment, Nabbit will jump out of nowhere and steal the contents of the chest.
New Super Mario Bros. Wii
New Super Mario Bros. U/New Super Luigi U
Enemies (New Super Mario Bros. Wii)
Enemies (New Super Mario Bros. U/New Super Luigi U)