A gunman opened fire inside the Catholic cathedral in the Brazilian city of Campinas on Tuesday and fatally shot four people praying in the pews before killing himself when police wounded him, authorities said.
Police identified the shooter as Euler Fernando Gandolfo, 49, a systems analyst with no criminal record. He entered the cathedral and sat down behind mainly elderly worshippers who remained to pray after midday mass.
"Security cameras show he came in and sat down on his own. A little later he started shooting the people in front of him," Campinas police chief Jose Henrique Ventura told reporters.
Police in the plaza outside rushed in when they heard the shots, Ventura said.
The gunman ran to the altar while firing at police and was hit in the side. He fell to ground and shot himself in the head, the police chief said. Gandolfo had two guns and 28 rounds left when he died.
"It was frightful," witness Alexandre Moraes told the GloboNews channel. "He entered and shot randomly at people. They were all praying."
Four people were shot dead and four others were wounded but Ventura said they were out of danger in hospital in Campinas, an industrial city 100 kilometers (62 miles) northwest of Sao Paulo, where the shooting took place.
Police have not established a motive.
Brazil had nearly 64,000 murders last year - more than any other country, according to the United Nations. However, random mass shootings are relatively rare, with few American-style shootings in schools or other public areas.
The rise in armed violence helped far-right politician Jair Bolsonaro win October's presidential election vowing to crack down on corruption, drug gangs and crime in the streets of Brazilian cities.
Bolsonaro, who takes office on Jan. 1, plans to ease gun laws to allow Brazilians to arm themselves against criminals, a policy his critics say will only increase the murder rate.