HONG KONG — Tens of thousands of demonstrators marching peacefully in one of several authorized rallies in Hong Kong on Sunday were dispersed with tear gas, ending a rare and cherished period of peace amid half a year of pro-democracy protests in the territory.

The march in Tsim Sha Tsui on the Kowloon side of the city had a clear message: The five demands of the protest movement, including universal suffrage and an investigation into the Hong Kong police, are not to be forgotten.

Protesters including the elderly and children, some of whom were carrying banners calling for the end of the Chinese Communist Party, said their fight must go on despite several key successes.

Residents voted overwhelmingly for pro-democracy candidates in local elections last week in what was widely interpreted as a resounding message of support for the cause. Those winners now control 17 out of Hong Kong’s 18 electoral districts. After a bipartisan push in Washington, President Trump has signed into law a bill to support the protesters.

“We feel better because of the election and the bill, but that’s not the end of the protest,” said Eric Chan, 33. “We need to bear in mind that we have a lot of demands which we cannot forget, and if we forget these demands, our friends, our comrades who have died or been prosecuted, their sacrifice would be for nothing.”

The rally was legal and permitted by authorities, but some protesters appeared to veer from the path approved for the march. Others hurled insults and made vulgar signs at the police, continuing the deep tensions between many in Hong Kong and the security forces that they say are acting with impunity. By late afternoon, shots of tear gas were fired, sending the crowd scattering and coughing.

Police said the protesters did not follow the approved route and attacked officers.

“As some radical protesters passed by Mody Road Garden via Salisbury Road, they hurled bricks at Police officers,” police said in a statement. “Police officers, in response, deployed the minimum necessary force, including tear gas, to stop their illegal acts.”

The protest movement was sparked in June by a government proposal to allow extraditions to mainland China. Critics said the bill would end Hong Kong’s prized freedoms and autonomy. The government has since withdrawn that proposal, meeting one of the five demands of the protest movement.

But the unrest has only grown, and revived a long-held demand for full, direct elections in the territory above the district level of last week’s vote.

In recent months, protests have intensified and grown more violent. Mid-November saw a tense new phase in which demonstrators tried to fortify two university campuses against police raids — leading to intense standoffs at both.

At Polytechnic University, where protesters rained molotov cocktails and arrows down on police, authorities sealed off all entrances and warned protesters that anyone inside would be arrested and charged with rioting.

That led some to barricade themselves in the campus and others to try daring, risky attempts at escape from bridges and sewers. The siege finally ended last week and a cleanup has begun. Authorities say it could take up to six months.

That exceptionally dangerous period, during which police threatened to use live ammunition, has been followed by a stretch of peace. Many saw the election as a rare opportunity for them to express their democratic will, and no tear gas was fired in any district for more than a week.

By sundown Sunday, police began clearing protesters gathering in the area and made several arrests. Officers used their shields and batons to move peaceful demonstrators.

“We have requested for a permit to hold the assembly, and it won’t expire for a few hours, but they are already scaring us away,” said Kenton Cheung, 32. “I don’t know what’s their intention, why they are always creating this intense environment in which we can’t express ourselves.”

“Police have initiated this conflict; that’s why people have fought back.”

An independent investigation into police conduct has been a main demand of protesters. Authorities counter that the existing oversight mechanisms are sufficient to detect any problems. Chris Tang, who took over this month as commissioner of police, called any inquiry into police behavior “unjust.”

Michelle Bachelet, the United Nations high commissioner for human rights, urged an independent investigation into the charges of police brutality as part of an inclusive dialogue.

“I appeal to the government to take important confidence-building measures, including a proper independent and impartial judge-led investigation into reports of excessive use of force by the police,” Bachelet wrote Saturday in the South China Morning Post.

China’s U.N. mission in Geneva on Sunday called the comments “inappropriate” and accused Bachelet of interfering in the country’s internal affairs. The mission said her article would only “embolden the rioters” to engage in more violence.