Sao Paulo state government officials reported at least 100 separate attacks on Friday, Saturday and Sunday, leaving 31 policemen, eight prison guards and four civilians dead. The others killed were suspected gunmen killed by police.
The bloodshed was unleashed by the First Command of the Capital (PCC in Portuguese) gang in retaliation for the transfer of imprisoned gang members to a remote prison.
Prisoners have also rioted in 36 penitentiaries, the government security office said.
Police say the violence was launched by the PCC, one of the most powerful of Brazil's organised crime operations, after the authorities transferred 765 prisoners to a new penitentiary 620km from the capital.
The transfer of prisoners, including Marcos Willians Herbas Camacho, or Marcola, the PCC chief, was an attempt to defuse a multi-prison rebellion allegedly planned for this weekend.
Sao Paulo - the country's industrial and business heartland and the world's third-biggest city with about 20 million people - has long been plagued by violent crime.
The clashes have left a trail of
It is the centre for drug-trafficking in Latin America's largest country, and a transit point for cocaine destined for Africa and Europe, as well as Brazil's domestic market.
However, the scale of the co-ordinated attacks on Friday and Saturday took police by surprise.
Jose Vicente da Silva, a former public security official, said: "The intelligence services need to anticipate these things so that it can take the necessary measures and stop them from happening. This was a big error."
Links between corrupt police officers and gangs fuelled the problem, he said.
New riots broke out in prisons across the state just as the authorities managed to bring others under control. The state prison service said rioting erupted in 36 of state's 106 prisons.