Denouncing government corruption, they called for a return to military rule - which Brazil saw from 1964 to 1985. In Rio de Janeiro, police fired tear gas at public sector workers protesting against cuts.
The protesters swept past security guards and smashed a glass door to get into the parliament chamber, where they shouted "general here, general here" and sang the national anthem.
It took police three hours to round up all the protesters, according to Reuters news agency. They were all detained.