A local barber hacked two boys to death and critically hurt a third in an axe attack on Tuesday in Baba Colony in Budaun, an officer said.
He was gunned down in an encounter hours later, he said.
A man who had recently opened a barber shop in the locality entered a house and attacked three brothers -- Ayush, 12, Ahaan alias Honey, 8, and Yuvraj, 10, with an axe, District Magistrate Manoj Kumar said.
Ayush and Ahaan died in the attack, while Yuvraj was rushed to a hospital with grievous wounds, he said.
The incident took place a few steps away from Mandi Police Post of Civil Lines Police Station.
Hours later, the assailant, identified as 22-year-old Sajid, was gunned down in an encounter, IG Bareilly range R K Singh told PTI.
Sajid had decamped from the house after killing the boys, and was found wearing the same blood-soaked clothes when he was confronted by police, he said.
"Our team came to know about him and chased him. He was seen in the forest of Shekhupur. When our SOG and police station team reached there, he fired at them. In the retaliatory firing he received a bullet wound and died," Singh said.
The IG said Sajid entered the house, met the boys' grandmother, and went to the second floor where the boys were.
After the incident, the boys' family members and some local residents vandalised shops and damaged a motorcycle, he said.
Uttar Pradesh Director General of Police Prashant Kumar said, "The incident took place at around 8.00 pm, when a person named Sajid entered a house located opposite to his shop, and attacked the children there. Two children were killed, while one child was injured. He (Sajid) fled from the spot."
He added, "The police immediately acted, and cordoned him off. He also fired at the police, and in retaliatory firing by the police, he was injured, and later he died."
Kumar said the area is now peaceful and under the watch of IG Bareilly range RK Singh, ADG Bareilly zone, and Bareilly Divisional Commissioner.
"The incident took place due to personal enmity, and there is no communal angle to it. We are monitoring the situation, and our social media cell is also monitoring it," he said.
The DG said there was only one person involved in the attack, Sajid, and no other. It was earlier reported that there were two people involved in the attack.
"As per information received at the headquarters, only one person was involved --- Sajid," Kumar said.
After the killings led to a ruckus in the area, the Senior Superintendent of Police ordered deployment of security there to bring the crowd under control.
Sajid used to run a barber's shop in the locality. His shop was located quite close to the house where the boys lived, the officer said.
The DM said the bodies of both the children have been sent for post mortem and the injured child has been admitted to the district hospital.
183 criminals killed in encounters since 2017: UP cops
UP: Molesters throw Dalit woman into hot cauldron
Alcoholic husband burns wife alive in UP's Budaun
Wanted criminal gunned down in encounter in UP
UP: Body of Dalit girl found, family alleges rape