Tension reigned in the Sheeshgarh town of the district after two teenagers from different communities made derogatory remarks about each other's religion on Instagram, police said on Saturday.
Police have detained two teens, one Hindu and one Muslim, in connection with the incident.
Around 9 pm Friday, some people from the Muslim community lodged a police complaint alleging that a 14-year-old student of Class 9 had made objectionable remarks on their religion on Instagram, Superintendent of Police (Rural) Raj Kumar Aggarwal said.
The officer said even though the Sheeshgarh Police Station assured them of action, the crowd, after coming out of the police station, surrounded the house of the teenager and raised slogans.
While the police struggled to placate the crowd, around 1.30 am, District Magistrate Shivakant Dwivedi, Commissioner Soumya Aggarwal, Inspector General of Police Dr Rakesh Singh, and other senior officers reached the spot.
The IG said 23 miscreants were detained in the matter on Saturday and heavy police force was deployed in Sheeshgarh.
Police detained the two teens late Friday night, Dr Rakesh Singh told reporters on Saturday.
The father of the Hindu teen said he was provoked by a comment made by the other boy on his religion, and when he responded to it, some people took the comment's screenshot and spread it online.
"My son's comment was made public after which there was a ruckus and the crowd gathered at my house," the man said.
Police Circle Officer (CO) Dr Tejveer Singh reached the spot after the incident was reported Friday night and called the police force from Shahi, Shergarh and Devarnia police stations. The RAF and PAC personnel were also called.
Officials battled to control the situation till midnight as the crowd sat on a dharna on the ground some distance away from the Hindu boy's house with the demand that the boy be brought out of the house.
The members of a Hindu organisation also became active at the same time. Police later brought both the boys and their fathers, and detained them only after the crowd was dispersed.
Senior Superintendent of Police (SSP), Bareilly, Ghule Sushil Chandrabhan said videography of the entire incident has been done and action has been initiated against those who spoiled the atmosphere.
Police said the matter is under control and there is peace.
Except for the headline, this story has not been edited by The Telegraph Online staff and has been published from a syndicated feed.