A court in Istanbul has ordered the release of seven journalists from Turkey’s oldest newspaper, Cumhuriyet, after nine months in prison and preliminary hearings in the country’s largest trial of journalists since last year’s coup attempt.

But the court ordered the continued detention of five other journalists – including the newspaper’s top executive and its most senior correspondents – in a partial defeat for press freedom in a country still reeling from the bloody failed putsch.

The decision followed five days of hearings, in which executives, lawyers and correspondents in one of the last big media outlets in the country critical of President Recep Tayyip Erdoğan and his ruling party were accused of abetting terrorist groups. The next set of hearings is expected in two months.

Several hundred people gathered outside the Çağlayan court in downtown Istanbul to show solidarity with the imprisoned journalists.

Inside, the lawyers defending Cumhuriyet’s staffers delivered closing arguments in a courtroom crowded with families, journalists and international observers.

The lawyers said the indictments against their clients were baseless and that the accusations would inspire fear in journalists working in Turkey, with one comparing it to the McCarthy era in the US in the 1950s, when people suspected of harbouring sympathies to the Communist party were purged from all walks of life based on flimsy evidence.

The landmark trial of the 17 Cumhuriyet staffers is widely seen by human rights and press freedom advocates as an attempt to intimidate journalists with baseless accusations.

Some of the journalists are accused of aiding supporters of Fethullah Gülen , the exiled cleric widely believed to have orchestrated last year’s coup attempt, despite Cumhuriyet’s long-running campaign against the movement.

“We want freedom of thought and the press for our country, we want an impartial and independent judiciary and fair trials for our country,” said Bahri Bayram Belen, one of the top defence lawyers in the case, in an interview with the Guardian during a recess in proceedings. “Without these, we cannot have a democracy.”

Over the previous four days of proceedings, the journalists who took the stand gave powerful testimonials about their incarceration. On Wednesday, Ahmet Șik, a veteran journalist who was imprisoned by the Gülenists for authoring a series of investigations into their abuse of power, laid out how Erdoğan’s ruling party had for years collaborated with the movement.

“Criminalisation of journalistic activities is a common feature of totalitarian regimes,” he said. “My experience shows that because of my journalistic activities I have managed to become the offender of the judiciary of every government and of every period. I am proud of this inheritance I will be leaving to my daughter.”

He added: “I was a journalist yesterday. I am a journalist today. And I will continue practising journalism tomorrow. That means the irreconcilable contradiction between us and those who want to strangle the truth will never end. In these dark days what we need is not further loss of the truth. More than anything we need more truth.”

Turkey remains the world’s largest jailer of journalists, with more than 150 behind bars. The authorities have closed down more than 170 media outlets since last year’s coup under the state of emergency, and 800 journalists have had their press cards revoked and passports confiscated.

Most of the local media has been co-opted by the government, and journalists and opposition officials say advertisers have fled from fledgling newspapers that criticise the government, for fear of repercussion. The unrelenting prosecution of journalists and the threat of government takeovers has also had a chilling effect, leaving Cumhuriyet as one of the lone voices critical of Erdoğan and his ruling party.

Cumhuriyet has angered the government by calling its purge of tens of thousands of civil servants, police and military officers, academics and journalists in the aftermath of the coup a “witch hunt”, and for criticising government policy on the conflict with the separatist Kurdistan Workers’ party (PKK).

It also embarrassed the government by revealing that the national intelligence service was smuggling weapons into Syria destined for rebels fighting Bashar al-Assad’s regime under the guise of humanitarian aid.