ANKARA, Turkey — A high school student who was jailed for allegedly insulting Turkey’s leader was released from custody on Friday after his arrest caused uproar and intensified fears that Turkey under President Recep Tayyip Erdogan is lurching toward more authoritarian rule.

The 16-year-old boy was arrested on Wednesday for allegedly calling Erdogan a thief, a day after he took part in a small left-wing student rally commemorating the death of a pro-secular army officer slain by Islamists 84 years ago.

His arrest at his Meram Technical and Vocational high school in Konya, central Turkey, sparked an outcry, with opposition parties denouncing it as the latest example of the government’s descent toward authoritarianism and its crackdown on free speech and dissent.

It is a crime in Turkey to insult the president, and others have been arrested on such charges before, but it was the first time a minor has been detained. Dozens of lawyers volunteered to defend the teen and petitioned for his release. At least three students were briefly detained during a protest Wednesday to denounce his detention, Cumhuriyet newspaper reported.

It wasn’t clear if the boy’s early release was connected to the huge amount of publicity over the case. Officials insist Turkey’s judiciary is independent of the state and it is not uncommon for Turkish detainees to be released from custody quickly.

Erdogan, who has dominated Turkish politics for the past decade as prime minister and as president since his election in August, was long regarded as a champion of democratic reforms. More recently, the Turkish leader has been accused of steering Turkey away from democracy by cracking down on protests, suppressing media freedoms and increasing police powers.

Earlier this month, police raided media outlets close to a movement led by a U.S.-based Muslim cleric – who is Erdogan’s strongest critic – and detained journalists and TV producers, a move that sparked U.S. and EU criticism.

“It is extremely difficult to speak of democracy, pluralism or say that the regime is a republic in a country where children are arrested for their speech,” the Ankara Bar Association said in a statement.

The boy, who can only be identified by his initials M.E.A. because of Turkish laws that protect the identity of minors, made a speech during the rally in which he said the students didn’t regard Erdogan as the president, but as the “thieving owner of the illegal palace,” according to court papers seen by The Associated Press.

His words referred to a vast government corruption scandal that has implicated members of Erdogan’s family, as well as a controversial 1,150-room presidential palace in the capital, Ankara, which Erdogan inaugurated in October. Erdogan has depicted the scandal, which forced four government ministers to step down, as a “coup” orchestrated by the followers of the U.S.-based cleric, Fethullah Gulen.

The boy walked through the gates of a detention center in Konya after a court there agreed to free him from police custody on Friday. The boy could still face up to four years in prison if he is charged and convicted. The Justice Ministry would however, need to give its consent for proceedings to go ahead.

The student denied during questioning that his words were intended as an insult to Erdogan, according to the court papers.