RIO DE JANEIRO — Violent clashes broke out on Friday between police officers and squatters here when the authorities dislodged thousands of families from a newly formed favela, or slum, in a complex of abandoned commercial buildings, focusing attention on the rising tension over surging rents and housing shortages.

Just two months before Brazil is to host the World Cup soccer tournament in Rio de Janeiro and other cities, police officers used tear gas and rubber bullets to disperse the squatters at a decaying property in the city’s gritty northern zone owned by Oi, one of the largest telecommunications companies in Brazil.

The squatters fought back by pelting the police with rocks, tossing firebombs and setting buses and police vehicles on fire. Even when officers managed to assert control over the settlement after hours of clashes, the protesters turned to looting nearby banks and a supermarket.