A rights activist in Kazakhstan who faced seven years imprisonment over his outspoken opposition to neighbouring China was unexpectedly freed on Friday as public and international pressure over his case mounted.

Serikzhan Bilash, whose activism in defence of Muslim and Turkic minorities in Chinese region of Xinjiang earned him global media attention, told AFP he struck a plea bargain with the court that allowed him freedom but will end his activism.

“I had to end my activism against China. It was that or seven years in jail. I had no choice,” Bilash said at a restaurant where he held a celebratory midnight feast with his family and about 40 supporters.

Bilash agreed to accept guilt over inter-ethnic incitement charges triggered by his call for an “information Jihad” against the Chinese authorities over their policies in Xinjiang earlier this year.

He will also be unable to leave the city of Almaty – Kazakhstan’s largest – for the next three months under the terms of his deal, he said, while noting he expected his supporters to continue taking the work of his informal Atajurt activist group forward.

“I had to do this for my family and my children,” he told supporters.

His release capped a dramatic night in Almaty, where some 200 hundred supporters surrounded the court where Bilash appeared and chanted for his freedom.

His lawyer Aiman Umarova had sounded the alarm earlier in the evening as she was unable to make contact with Bilash, who had arrived at the courthouse before her and was immediately taken in by authorities.

Umarova refused to sign the plea bargain, insisting on her client’s innocence, meaning Bilash had to find another lawyer to sign off on the deal.

“I refuse to put my name to any deal that was signed under pressure,” Umarova said.

Bilash had previously been held under house arrest after being detained and flown to the capital, Nur-Sultan, in March.

Critics connected his arrest to pressure from Kazakhstan’s economically powerful neighbour, China. Kazakhstan, an oil-rich, landlocked country of 18 million people has positioned itself as the “buckle” in President Xi Jinping’s flagship Belt and Road international infrastructure drive.

An estimated one million ethnic Uighurs and other mostly Muslim minorities are thought to have been sent to “vocational education centres” in Xingjiang, which numerous studies and reports say are harsh internment camps.

In July, Chinese officials claimed most people sent to detention centres in Xinjiang had “returned to society”, but the US state department said there was no evidence to support this.

With a population of at least 1.5 million, Kazakhs are the second-largest Turkic group in Xinjiang after the Uighurs.

In July a court in Nur-Sultan ruled to transfer his case to Almaty, where the family of Bilash – an ethnic Kazakh who was born in Xinjiang but obtained Kazakh citizenship as an adult – are based.

Fiery orator Bilash had told the court Beijing was perpetrating a “genocide” against Turkic minorities in Xinjiang.

Kazakhs living in Kazakhstan have used Bilash’s group Atajurt to appeal to the Kazakh government to lobby China for their relatives’ release.

Kazakhstan’s foreign ministry has engaged in quiet diplomacy with major trade partner China on Xinjiang but has been reluctant to promote its efforts given sensitivities over the region.

Last year the ministry said China had allowed 2,500 ethnic Kazakhs to leave the country and enter Kazakhstan “as a kind gesture” but refused requests for further information.