BEIJING — Hu Jia, one of China’s most prominent social activists and a leading political dissident, was released from prison on Sunday after completing a 42-month sentence for state subversion, his wife, Zeng Jinyan, stated in a post on the American microblog Twitter.

Mr. Hu, 37, was detained in December 2007, shortly after testifying on China’s human-rights situation before a European Parliament committee, and was sentenced to prison in early 2008.

The authorities had rejected repeated requests by Ms. Zeng that he be released early on medical grounds because a hepatitis-B infection left him with a serious case of cirrhosis. Ms. Zeng, who is also a political activist and blogger, was herself subjected to harassment during her husband’s confinement, and said in an interview this month that the authorities were trying to force her and her 3-year-old daughter from their apartment in Shenzhen.

Early Sunday, Ms Zeng wrote on Twitter that Mr. Hu had arrived home at 2:40 a.m. Beijing time.

“A sleepless night,” she wrote. “peace. happiness. he needs to rest for a while. thank you to everyone please forgive us if we have caused you any inconvenience.”