HONG KONG — A mass protest in Hong Kong came to an abrupt and chaotic end Sunday when demonstrators attacked plainclothes police officers, leading authorities to respond with pepper spray, tear gas and arrests.

Relations between the public and the Hong Kong Police Force have collapsed during the months of protests that began last year in response to the government’s attempt to pass a bill that would allow for extraditions to mainland China. The bill was withdrawn, but the alleged misuse of force by the police, and the government’s refusal to launch an independent inquiry into police conduct, have become another grievance.

Sunday brought a return to the sporadic violence that has erupted occasionally around the largely peaceful anti-government movement, now in its eighth month. The conflict underscored the risk of using plainclothes police officers to respond to protesters, a highly controversial tactic that has sowed mistrust and prompted scuffles multiple times since the demonstrations began in June.

Tens of thousands of people gathered in Chater Garden in the city’s Central district on Sunday to rally against the Communist Party and call for universal suffrage in the territory. Organizers were denied a permit for a march, but police did approve a rally as long as it stayed in one place. The crowd filled the park and protesters spilled into the nearby streets.

The turnout appeared to be the largest since an authorized protest on New Year’s Day, when organizers said over a million people gathered to demonstrate.

Police said some protesters began vandalizing buildings and tossing water bottles at officers, prompting them to cancel the event. Police had sent community liaison officers to deliver the message to the rally’s organizers, they said.

The plainclothes officers told organizers that the rally was being called off at about 4 p.m., according to Ventus Lau, a member of the Hong Kong Civil Assembly Team. Lau asked to see an officer’s identification card, he said, but the officer initially resisted. Once he saw the officer’s badge, Lau said, he attempted to clear the park, but the altercation had drawn a crowd of angry protesters and fighting broke out.

At about 4:30 p.m., a small group of riot police entered the park in what looked to be an effort to assist their injured comrades and clear the area.

A group of protesters chased injured and bleeding plainclothes officers across the street, where they attempted to find safety in a building. They were unable to enter because the doors were locked. Cornered, three of them were beaten by protesters with umbrellas and batons. One protester attempted to hit them with a brick. More police rushed in to disperse the crowd.

Moments later, police fired multiple rounds of tear gas, sending protesters and dozens of migrant domestic workers who gather in the area on their day off fleeing. The three people beaten — two men and a woman — left in ambulances with their heads bandaged.

Backed by an armored vehicle and water cannons, police raced down the nearby streets to clear protesters.

Police said two officers from the Police Community Liaison Office were speaking with rally organizers when they “were suddenly surrounded and beaten up brutally by a large group of rioters with wooden sticks and other weapons.”

“They were left with bloody head injuries,” police said in a statement. “Such appalling acts are not to be condoned. The Police will endeavor to bring the assailants to justice.”

Lau was arrested Sunday evening, local media reported.

The Hong Kong government also condemned the attacks, calling them “outrageous,” and accusing “rioters” of exploiting peaceful public assemblies “as a cover for vandalism and attacks.”

Police Commissioner Chris Tang was grilled last week by district councilors about the force’s use of plainclothes officers, who often have no visible identification and wear masks to obscure themselves further. One district councilor held up photos of plainclothes officers and asked Tang whether he himself could identify them. Tang responded that he could not.

Sunday’s protest, featuring a variety of speakers and an Italian opera singer, drew a crowd of diverse ages. Many of the protest materials being handed out were styled for the upcoming Lunar New Year holiday.

The government has drastically scaled back its own celebrations this year — canceling a fireworks show and limiting the size of the traditional holiday markets selling food and flowers. But independent fairs have popped up offering items featuring popular protest slogans and icons.

Faning Yam, a 27-year-old waitress, stood near a suitcase filled with 3,000 cards she had printed that people filled out with New Year’s messages to be delivered to imprisoned protesters. “Chinese New Year is coming and we need to bring some encouragement to our brothers and sisters who are in jail for us,” she said.

Cheng Keng Leong, a pro-democracy district councilor, handed out fai chun, a traditional New Year’s decoration, emblazoned with the slogan “five demands, not one less.” The mantra was popularized after Carrie Lam, Hong Kong’s leader, withdrew the extradition bill but refused to meet the protesters’ other demands, including universal suffrage and an independent inquiry into police conduct.

“We are not giving up,” Cheng said, “even if [the government] is abusing its power and using the police as a tool.”

Lam was questioned about the police last week by lawmakers during a raucous session at the Legislative Council. She dismissed the concerns as a smear campaign aimed at weakening the police’s ability to enforce the law.

Cheng dismissed Lam’s comments as “useless.” He referred to November’s district council elections, in which pro-democracy candidates routed the pro-Beijing camp.

“The voting results are very clear,” he said. “They want the five demands.”

Tiffany Liang contributed to this report.