HONG KONG — A 24-year-old mainland Chinese music student living in Hong Kong on Thursday became among the first to be convicted on a charge related to the months-long protests in the city, receiving six weeks in prison for carrying an expandable baton.

The student, Chen Zimou, is also the first mainland Chinese person to be charged with a ­protest-related offense — a reality that has put him and his family under intense pressure from Chinese authorities and Chinese nationalists online who have branded him a traitor.

Although Chen pleaded guilty to carrying the weapon, he has maintained that he was not actively participating in protests when he was arrested. He also said in an interview that he did not realize the baton, which extends to about 30 inches, is illegal in Hong Kong. Similar batons are legal in mainland China.

Chen, a music major at the University of Hong Kong and a part-time piano teacher, told The Washington Post in an earlier interview that he was on his way home in the neighborhood of Sheung Wan on July 28 when he ran into a large group of protesters occupying roads near Beijing’s liaison office in the city.

He approached police officers to let him through their cordon to get home, he said, but was stopped and searched instead. When riot police officers found the baton, they arrested him.

“I thought it had to be a mistake, or maybe they were confused and thought I was a protester,” said Chen, who admitted he was wearing black at the time — the color of Hong Kong’s political protesters — but he said he was just trying to get home. “I tried to explain.”

Chen said he had bought the baton on the Chinese e-commerce website Taobao and picked it up in Shenzhen, the Chinese city that borders Hong Kong, where he teaches private piano lessons. Spooked by gang attacks against protesters and commuters at the Yuen Long subway station on July 21, Chen said he believed he needed something for his own “self-defense.” He said he had already been assaulted once in the past year.

More than 3,000 people have been arrested since protests began over an unpopular government proposal that would allow extraditions to mainland China. Although the bill has been withdrawn, demonstrations have tapped into long-held sentiments in Hong Kong that the city’s autonomy is being eroded by Beijing and have revived a call for direct elections.

Of those arrested, however, only a few hundred have been charged. Cases from earlier in the summer are still making their way through Hong Kong’s judicial system, which lawyers say is under great strain over the huge number of detentions and mass arrests as a crackdown on the protest movement intensifies. A small number have been convicted of offenses, including a 16-year-old also found guilty on Thursday of possessing an offensive weapon — in this case, a laser pointer.

As political tensions deepen, mainland Chinese students, residents and tourists in Hong Kong have often found themselves caught in between — sometimes targeted by — Hong Kong protesters who believe them to be against their cause and at other times threatened by mainland authorities for even mild protest sympathies.

Chen describes himself as more “liberal” than his compatriots from the mainland. He has a Facebook account — although the social networking site is banned in mainland China — on which he shares political views that encourage dialogue and moderation between both sides. Speaking to The Post two weeks ago, he faulted Hong Kong’s government for responding to protesters’ demands too slowly, but he also denounced violence from protesters.

His social media pages have been flooded with threats and insults from Chinese users, who have said that he does not deserve his People’s Republic of China passport, that he should die in jail and that he should never return to the mainland. Chen deleted his account on the Chinese microblogging platform Weibo after it was inundated with death threats.

“I am sorry for their inability to deal with their own emotions and recognize the facts,” he said of the commenters.

Yet, Chen admitted, “I recognize I may not be able to go back to the mainland. I’m not really sure how officials see me now.”