BEIJING — In public, he was a twice-divorced computer science professor dedicated to his students and to caring for an elderly mother who suffers from Alzheimer’s disease.

In private, the professor, Ma Yaohai, 53, led a life that became intolerable to Chinese authorities: for the past six years, he was a member of informal swingers clubs that practiced group sex and partner swapping. In online chat rooms, his handle was Roaring Virile Fire. He organized and engaged in at least 18 orgies, most of them in the two-bedroom apartment in Nanjing where he lived with his mother, according to prosecutors.

On Thursday, a court sentenced the randy Mr. Ma to three and a half years in prison, a severe penalty for a crime that the Chinese government calls “crowd licentiousness.” Mr. Ma, now China’s most famous swinger, remains defiant and plans to appeal, saying his sex life is his own business, not subject to the law as long as he causes no social disturbance, according to his lawyer, Yao Yong’an.

“Privacy needs to be protected,” Mr. Yao said in an interview.

The case of Mr. Ma, who was arrested in August and went on trial last month, has drawn attention across China not only for its titillating details, but also because it raises questions about an authoritarian government’s attempts to curb sexual freedom and limit privacy in a society where rapid economic growth and the ubiquity of the Internet have upended traditional values.