Violence flared on Tuesday in the centre of Madrid as baton-wielding police charged crowds and fired rubber bullets at demonstrators who had tried to surround the country's parliament building.

Some 32 people were injured, including several police officers, and several dozen were arrested after police broke up the "surround the parliament" demonstration against Mariano Rajoy's government shortly after it overran its 9.30pm deadline.

Several hundred protesters remained peacefully on the streets near the parliament building late on Tuesday night. They are demanding the resignation of the government and the king, as well as a rewrite of Spain's constitution.

Authorities have estimated the number of protesters at 6,000 – relatively small by Spanish standards.

Several key parts of the peaceful indignado protest movement, which successfully occupied city squares around Spain last year, had refused to support Tuesday's demonstration.

Protesters complained that police officers hid badges so they could not be identified. "They don't wear them and we back that when they deal with violent groups. Give them hell and that's it!" tweeted Jose Manuel Sanchez, of the SUP police union.

Tuesday's protests came shortly after Catalan regional prime minister Artur Mas called a snap election for 25 November amid a growing wave of support for separatism in Spain's wealthiest region.

Independence was set to be the key issue in elections, bringing Rajoy a fresh set of problems as he struggles with 25 percent unemployment and a double-dip recession.

A radical association of retired Spanish servicemen, the Spanish Military Association, claimed that the constitution would oblige the army to arrest and try separatists if they unilaterally declared a separate country.