Media playback is unsupported on your device Media caption The demonstration soon became hijacked by a group of masked men, as Wyre Davies reports

Protesters demonstrating in support of teachers receiving better pay in the Brazilian cities of Rio de Janeiro and Sao Paulo have clashed with police.

The centre of Rio was packed with more than 10,000 people marching peacefully.

But as it got dark, some protesters threw firebombs at public buildings and riot police responded with tear gas.

A similar protest in Sao Paulo also ended in violent confrontation with police after many banks were ransacked by hooded protesters.

Analysis Brazil is getting the kind of attention it could really do without only eight months before thousands of visitors are due here for the World Cup. The authorities, both here in Rio and at federal level, insist they have responded to many of the protesters' demands, particularly in areas like promising to spend more on health and education provision. The latest demonstrations in Rio were among the most violent yet, even though it had started out with at least 10,000 overwhelmingly peaceful teachers and other trades unionists. Who exactly the masked youths, known as the Black Blocs, are isn't clear. But the anarchy they sowed in the historic centre of Rio doesn't bode well and may lead to a radical change of approach - both from the authorities and those protestors who want to demonstrate peacefully.

Brazil's security situation is a challenge to cities that will play host to the 2014 World Cup and 2016 Olympic Games.

The latest demonstration took place over several hours and was peaceful at first.

But once night fell, violent incidents broke out as at least 20 "black bloc" anarchists smashed a City Hall gate while others broke into banks and tried to break break into ATMs. Some banks were set alight.

Demonstrators also torched a bus on busy Rio Branco Avenue, and took furniture out of banks to use in barricades as the stand-off off with police continued.

Authorities used tear gas to restore order.

"Without the police, there is no violence. When they are there, there always is," said anarchist Hugo Cryois, 23, who had a gas mask dangling from his neck.

"I came prepared," he said. "You can't trust them."

Teachers have been demanding a pay increase for two months. About 50,000 people were estimated to have marched to support them before the violence broke out, but police would only confirm the 10,000 estimate.

Image caption A mostly peaceful teachers' protest in Rio ended in violent confrontation after it was hijacked by a small but violent group of masked young men

Image caption Monday's demonstration comes in the wake of citywide strikes by unionised education workers in Rio over the past few weeks

Image caption A BBC correspondent in Rio says there have been several anti-government protests in Brazil, but not as violent as this

Image caption An incendiary device was fired toward a government building in Rio

Image caption Riot police tried to extinguish a fire on a bus allegedly set by the Black Bloc group, which was blamed for the violence