SAO PAULO — Thousands of protesters took to the streets of Brazil's two biggest cities Thursday to rage against 10-cent increases in bus and subway fares, and some clashed with police.

The demonstrations came as Brazil prepares for this weekend's start of the Confederations Cup soccer tournament, and looks ahead to a visit by Pope Francis next month.

Protesters in Sao Paulo and Rio de Janeiro were led by a mix of groups, mostly university students, but authorities said there were also bands of anarchists who seek out fights with police.

Officials said roughly 5,000 protesters were in the streets of Sao Paulo's central area, where they clashed with police who fired tear gas trying to disperse the crowd. Police said 40 people had been detained, some with knives and gasoline bombs.

Traffic in Sao Paulo, always heavy, ground to a halt in much of the metropolis because of the protests.

Police in Rio de Janeiro said about 2,000 people protested there.