ISTANBUL — It was 4 a.m. one December day when Tunca Öğreten heard loud kicks against the door of his apartment.

Twenty anti-terrorist police officers armed with rifles knocked it down and ransacked the home Öğreten shared with his fiancee, before arresting him.

He was kept in a police cell, barely 10 feet square, with four other men for 24 days. With no toilet or shower, he was forced to wash himself by saving up water bottles and to urinate into an empty bottle.

“I begged them, ‘Take me to prison,’” Öğreten said. “Prison would be better than this torture.”

A judge eventually ordered him to jail, where he languished for 10 more months.

Tunca Öğreten, a Turkish journalist who spent one year in jail without trial, at home in Istanbul. Danielle Villasana / for NBC News

Öğreten, a 37-year-old journalist, is accused of crimes against the state for reporting on hacked emails that accused a company run by Turkey’s energy minister of being involved in trading oil from the Islamic State. Almost two years after the raid, he still awaits trial.

Öğreten is far from alone.

Turkey, a key NATO ally, has detained tens of thousands of teachers, lawyers, students, judges and other officials amid a crackdown on dissent by the government of President Recep Tayyip Erdogan after the failed coup of 2016.

The country’s 384 prisons and detention facilities are already overcrowded, holding 224,974 inmates as of March 20, according to the Ministry of Justice — almost 7 percent over their official capacity.

Turkey now has the third-highest per capita prison population in Europe, behind only Russia and the tiny post-Soviet dictatorship of Belarus. (The U.S. has the highest rate in the world.)

To fix the problem, the ministry announced in December that it will build 228 more prisons over the next five years.

“Prison wings designed for 20 people are being used to keep up to 45,” opposition CHP party spokesman and former lawmaker Baris Yarkadaş told NBC News. “Some of them must sleep on the floor, others develop respiratory sickness. The solution of Erdogan’s government is just to keep building more prisons.”

Justice Minister Abdulhamit Gul did not immediately respond to a request for comment.

A NATO ally 'isn't acting like one'

Images of civilians climbing on tanks and soldiers being violently beaten with belts dominated news coverage of the aborted coup on July 15, 2016, in which 251 people died.

Pro-Erdogan supporters wave Turkish national flags during a rally in Istanbul on July 18, 2016, a few days after the failed coup attempt. Aris Messinis / AFP - Getty Images file

But Erdogan’s triumphant revenge on dissenters has proved no less brutal.

He immediately blamed the coup on influential cleric Fethullah Gulen, 77, a former Erdogan ally who lives in self-imposed exile in Pennsylvania; Gulen denies involvement and the White House has resisted demands for his extradition.

Turkey describes Gulen followers as members of the Fetullah Terrorist Organization (FETO) and accuses them of a long-running campaign to overthrow the state through the infiltration of state institutions, particularly the military, police and judiciary.

At least 169,000 state workers, soldiers or others have been suspended or dismissed from government jobs in the crackdown, according to the Ministry of Justice. Activist websites such as TurkeyPurge.com, which is blocked inside the country, put the numbers even higher. More than two years after the coup, the roundups continue; 12 accused coup members were detained this month according to the official Anadolu news agency.

“These days you only have to have a bank account or study at a university with Gulen connections and the courts consider that you are a terrorist,” Adnan Seker, a lawyer who has been arrested for alleged FETO links, said. He denies any involvement in the coup. “I do not even find sympathy for those who adopt violence.”

Turkish cleric Fethullah Gulen is pictured in his home in Saylorsburg, Penn., on July 29, 2016. Charles Mostoller / Reuters file

Erdogan has also used a two-year state of emergency, which ended only last month, to detain anyone suspected of being linked to outlawed groups such as the Kurdish separatist PKK, which is recognized by the U.S. and Turkey as a terrorist organization.

Among those is Andrew Brunson, a North Carolina evangelical pastor who was arrested in 2016 on charges of espionage and “committing crimes on behalf of terror groups without being a member.” He has been released from prison but remains under house arrest and is expected to face trial next month.

Brunson, 50, has lived in Turkey for 23 years, running the small Resurrection Church in the western city of Izmir. The Erdogan-linked Daily Sabah newspaper reported last month that a prominent member of Brunson’s congregation had shared PKK links on social media.

Secretary of State Mike Pompeo has appealed to Turkish Foreign Minister Mevlut Cavusoglu in person for the pastor’s release from house arrest, calling him “an innocent man.”