Police and small groups of protesters have clashed in Brazil's two biggest cities at the end of peaceful demonstrations demanding better pay for teachers and affordable housing.

I can't believe this is my Brazil, my city. This isn't democracy.

Witness

Most demonstrators headed home in Rio de Janeiro and Sao Paulo on Tuesday night but hundreds of masked members of the so-called Black Bloc anarchist group started hurling petrol bombs, rocks, bottles and pieces of wood at police who had accompanied the protest marches.

Police then used tear gas and percussion grenades to disperse the activists.

"I can't believe this is my Brazil, my city," screamed one man, eyes teared up from floating gas. "This isn't democracy."

In Rio, police said about 4,000 demonstrators gathered in the city centre to mark National Teachers Day and show their support for public school teachers who have been on strike for more than two months seeking higher pay.

Similar scenes of violence played out in Sao Paulo, where Black Bloc activists also attacked police, bringing an early end to a march by several hundred demonstrators towards the governor's palace.

Earlier, activists of the "Roofless" movement tried to invade the Sao Paulo city council building, but were pushed back by police. They later regrouped in front of the city hall in a peaceful rally that lasted about two hours.

Last week, a largely peaceful rally of about 20,000 demonstrators turned violent in Rio when small groups of masked protesters started throwing rocks and fire bombs at banks, stores and restaurants and set fire to a passenger bus.

Source: Agencies