ISTANBUL — An Istanbul court on Wednesday ordered the release of a group of leading Turkish human rights campaigners and two foreign co-workers — a German and a Swede — in a surprise softening in Turkey’s yearlong prosecutions after a 2016 coup attempt.

The decision, which came just before midnight, was an interim ruling, and the case against the 11 human rights workers will continue. But eight of the accused who were still being held in prison, including the two foreign citizens, were ordered released by the judge. Two of the Turkish citizens will remain under a travel ban, preventing them from traveling abroad.

When 10 of the human rights leaders were detained by the police in July as they were attending a workshop at a resort hotel on Buyukada, one of the Princes’ Islands, near Istanbul, Turkey’s nongovernmental and civil society organizations were shaken.

The charges against the workers — that they were aiding a terrorist organization — were similar to those being used to detain tens of thousands of Turkish citizens since the failed coup.

Fethullah Gulen, an Islamist cleric living in the United States, has been blamed for masterminding the coup attempt, but thousands of others, including political opponents and critics of the government, have been imprisoned in the widespread crackdown.

The human rights workers included several senior Turkish representatives of Amnesty International, two foreign consultants, a prominent human rights lawyer and a project specialist for the United Nations World Food Program. The chairman of Amnesty International Turkey, Taner Kilic, was later included in the indictment.

In a one-day hearing that lasted late into the night, some of the Turkish citizens were charged with having links to followers of Mr. Gulen, or people who used an encrypted application on their cellphone that prosecutors say was employed by the coup plotters.

In a sign of the government’s suspicion of nongovernmental organizations, the indictment charged the detainees with organizing meetings and activities to generate a social movement like the protests that took place in Taksim Square in Istanbul in 2013.

In addition, the foreign consultants were accused of giving training sessions on how to conceal data from the police and the authorities.

The defendants disputed the charges and pleaded not guilty. Some of them claimed that the evidence was fabricated or just wrong. Most of them refused the statutory offer to repent of their actions in order to receive a more lenient sentence.

The two foreigners — Peter Steudtner, 46, a German, and Ali Garawi, 50, a Swede who also has American citizenship — were independent consultants conducting training in stress relief and data security for the small group of human rights campaigners.

Mr. Steudtner’s detention ignited a diplomatic dispute between Germany and Turkey. The Germans accused the Turks of taking hostages to pressure Germany to hand over several wanted Turkish citizens.

Germany announced a reorientation of its policy toward Turkey, calling for a slowdown of talks for Turkey’s accession to the European Union and the suspension of financial programs. It also cautioned Germans about traveling to Turkey and warned investors against doing business there.

Mr. Steudtner denied all charges. “I have always taken a nonviolent approach” and have worked “within a legal framework,” he said at the hearing, describing his career of 20 years in promoting peace and human rights in developing countries. “I never worked with a terrorist organization; it is completely against my personal convictions.”

He said computer files that were listed in the indictment as evidence appeared to have been fabricated, and one document contained nothing more than simple instructions on how to transfer computer files from a phone to a storage card.

Mr. Garawi spoke emotionally of his bewilderment at the indictment and the toll that three months of imprisonment had taken on his health.

A refugee who fled Iran after his father was killed, Mr. Garawi said he had spent 20 years working in nonprofit organizations to help others. “I have devoted my life to alleviating the effects of war because of the trauma I went through as a young child,” he said, “only to come here and experience extreme pain for the last three and a half months.”

A version of this article appears in print on , on Page A6 of the New York edition with the headline: Turkish Court Releases 8 Human Rights Workers in a Surprise Move. Order Reprints | Today’s Paper | Subscribe