A gunman stormed a house party and killed 11 people, including his former wife and 8-year-old son, before shooting himself in the head during a New Year's party in the southeastern Brazilian city of Campinas late on Saturday.
Police in the state of São Paulo said the shooter, identified as 46-year-old Sidnei Ramis de Araújo, was believed to have been angry over a split with his wife, Isamara Filier, 41, and their son João Victor.
Three other people were still in hospital, police said, while four people survived the attack unharmed, including one party attendee who managed to flee to a bathroom and phone the police when the shooting began.
A police spokesperson said survivors had reported the shooter jumping over a fence surrounding the house just before midnight, then bursting through a door and firing as he berated Filier for taking their son.
Araújo possibly sought to take advantage of the commotion of New Year's Eve to disguise the shooting, police said.
One neighbour told local television that he and his family heard shots, but had thought they might be fireworks until one of the wounded ran to their property, bleeding and pleading for help.
Despite high rates of crime and violence in Brazil, including significant problems with assaults against women, the attack alarmed Latin America's biggest country on a holiday associated with family gatherings.
Gun deaths in Brazil are common in heists, holdups and in confrontations among police, drug gangs and other criminals, but targeted mass shootings are rare.
Police said Araújo, reported by local media to be a laboratory technician, had used a 9mm pistol and carried two additional clips, extra ammunition, a knife and unspecified but unused explosives.
Investigators were analyzing the explosives in addition to a cell phone and audio recorder found in a car he parked outside the home to determine whether Araújo left any sort of message about his attack.
Police said they did not yet know if Araújo had a history of violence, or whether he had been known to physically harm or threaten his former wife before the attack.
Campinas, an industrial and university city of more than 1 million residents, is located about 100km northwest of Brazil's biggest metropolis São Paulo.