Anarchist group mars Brazilian teachers' march
Masked demonstrators destroy cash dispensers, following a peaceful teachers protest demanding better working conditions and against police beating, on Oct. 7, 2013 in Rio de Janeiro. [AFP]

Thousands marched in Rio de Janeiro Monday to support teachers seeking pay hikes before masked anarchists turned to violence, setting fires, breaking into buildings and smashing a City Hall gate.

The 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 open ATMs and set some alight.

Demonstrators also torched a bus on busy Rio Branco Avenue, and pulled furniture out of banks to use in barricades as they squared off with police.

Authorities used tear gas to get the crowd under control.

"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 who have been pressing for a pay raise for two months said 50,000 people marched to support them before the violence broke out. Police would only confirm the 10,000 figure.

Brazil's security situation is an ongoing challenge in this city that will play host to the 2014 World Cup and 2016 Olympic Games.