ISTANBUL — When a Turkish court unexpectedly ruled Tuesday to acquit civil society activists charged with attempting to overthrow the government, human rights advocates and others who had placed little faith in Turkey's judiciary reacted with shock, saying it seemed too good to be true.

Sixteen activists, including the prominent philanthropist Osman Kavala, were accused of instigating protests in 2013. Their advocates said the charges were political and part of a broader campaign by the government of President Recep Tayyip Erdogan to stamp out dissent. Even so, the judges acquitted nine of the activists and ordered the release of Kavala, the only defendant in custody.

But Kavala never emerged from prison, and by nightfall, prosecutors had leveled grave new accusations, saying he was being investigated for seeking "to disrupt the constitutional order" in connection with a failed coup attempt in July 2016 and would remain in custody.

It was not clear Tuesday whether seven defendants who live abroad and were tried in absentia would face further legal action.

The whipsaw developments raised new questions about political pressure on Turkey's judiciary and refocused attention on the government's incessant pursuit of its perceived opponents. Kavala's supporters were crestfallen after an afternoon of giddily anticipating his release gave way to familiar feelings of impotence and anger.

Amnesty International, which had hailed the acquittals as a "touchstone for Turkish justice," said a few hours later that the new accusations against Kavala smacked of "deliberate and calculated cruelty."

"It is time for Turkey to end the relentless crackdown on dissenting voices. Osman Kavala must be immediately released from prison," Milena Buyum, Amnesty International Turkey's campaigner, said in a statement.

Kavala and the 15 other defendants were accused of fomenting the 2013 Gezi Park protests, which began as a sit-in in Istanbul against a plan to build a shopping mall over a city park and grew into nationwide protests against Erdogan, who was then prime minister.

Their trial was closely watched as a test of Turkey’s political climate at a moment when the government is clamping down on enemies and opponents and Erdogan has been accused of strengthening his influence over the judiciary.

The crackdown accelerated after the coup attempt in 2016. The authorities have arrested thousands of followers of Fethullah Gulen, a U.S.-based Turkish Muslim cleric accused of masterminding the failed coup. Thousands of other people the government linked to the Gulen movement were dismissed from their jobs.

The dragnet reached beyond Gulen’s followers and included members of opposition political parties, journalists, university professors, civil society activists and others.

The defendants in the Gezi trial included filmmakers, an early childhood development specialist, an architect and urban planners.

A 657-page government indictment accused the defendants of inciting the protests with the backing of George Soros, the billionaire philanthropist. The indictment cast the Gezi demonstrations as part of a vast conspiracy linked to international protest movements such as Occupy Wall Street and as the precursor to the 2016 coup attempt.

Kavala, 63, the best-known defendant in the case, founded Anadolu Kultur, an organization that promotes diversity, culture and human rights. He had been in custody since November 2017. In December, the European Court of Human Rights said in a ruling that Turkish authorities had provided insufficient evidence for his continued detention and ordered his release.

“We really were not expecting this,” Can Atalay, a lawyer and one of the defendants, told reporters after the acquittals. “What can we say? We can hope that things will change for the better.”

Turkey’s judiciary faces another test Wednesday, when a separate trial involving human rights activists charged with terrorism-related crimes is expected to conclude. The defendants in that case include Idil Eser, Amnesty International’s former Turkey director, and 10 other human rights workers who were arrested in 2017.